From d3b55c361286eaed09566c184e2017bdd2dec4c9 Mon Sep 17 00:00:00 2001 From: Augustin Degomme Date: Fri, 9 Apr 2021 03:29:52 +0200 Subject: [PATCH] use previous buffer check feature in MPI checks, to crash when a buffer overflow is detected and provide good information. --- src/smpi/bindings/smpi_pmpi_coll.cpp | 114 +++++++++++++++--------- src/smpi/bindings/smpi_pmpi_file.cpp | 4 +- src/smpi/bindings/smpi_pmpi_request.cpp | 19 ++-- src/smpi/bindings/smpi_pmpi_type.cpp | 28 +++--- src/smpi/bindings/smpi_pmpi_win.cpp | 12 +-- src/smpi/include/private.hpp | 18 +++- src/smpi/mpi/smpi_win.cpp | 85 ++++++------------ 7 files changed, 150 insertions(+), 130 deletions(-) diff --git a/src/smpi/bindings/smpi_pmpi_coll.cpp b/src/smpi/bindings/smpi_pmpi_coll.cpp index b80f397074..30eef29719 100644 --- a/src/smpi/bindings/smpi_pmpi_coll.cpp +++ b/src/smpi/bindings/smpi_pmpi_coll.cpp @@ -62,10 +62,11 @@ int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm c int PMPI_Ibcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm, MPI_Request* request) { + SET_BUF1(buf) CHECK_COMM(5) - CHECK_BUFFER(1, buf, count) CHECK_COUNT(2, count) CHECK_TYPE(3, datatype) + CHECK_BUFFER(1, buf, count, datatype) CHECK_ROOT(4) CHECK_REQUEST(6) @@ -99,17 +100,19 @@ int PMPI_Igather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request* request) { CHECK_COMM(8) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) int rank = comm->rank(); if(sendbuf != MPI_IN_PLACE){ - CHECK_BUFFER(1,sendbuf, sendcount) CHECK_COUNT(2, sendcount) CHECK_TYPE(3, sendtype) + CHECK_BUFFER(1,sendbuf, sendcount, sendtype) } if(rank == root){ CHECK_NOT_IN_PLACE_ROOT(4, recvbuf) CHECK_TYPE(6, recvtype) CHECK_COUNT(5, recvcount) - CHECK_BUFFER(4, recvbuf, recvcount) + CHECK_BUFFER(4, recvbuf, recvcount, recvtype) } else { CHECK_NOT_IN_PLACE_ROOT(1, sendbuf) } @@ -159,12 +162,14 @@ int PMPI_Igatherv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, voi MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request* request) { CHECK_COMM(9) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) int rank = comm->rank(); - CHECK_BUFFER(1, sendbuf, sendcount) if(sendbuf != MPI_IN_PLACE){ CHECK_TYPE(3, sendtype) CHECK_COUNT(2, sendcount) } + CHECK_BUFFER(1, sendbuf, sendcount, sendtype) if(rank == root){ CHECK_NOT_IN_PLACE_ROOT(4, recvbuf) CHECK_TYPE(6, recvtype) @@ -179,7 +184,7 @@ int PMPI_Igatherv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, voi if (rank == root){ for (int i = 0; i < comm->size(); i++) { CHECK_COUNT(5, recvcounts[i]) - CHECK_BUFFER(4,recvbuf,recvcounts[i]) + CHECK_BUFFER(4,recvbuf,recvcounts[i], recvtype) } } @@ -228,9 +233,9 @@ int PMPI_Iallgather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, v MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request) { CHECK_COMM(7) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) int rank = comm->rank(); - CHECK_BUFFER(1, sendbuf, sendcount) - CHECK_BUFFER(4, recvbuf, recvcount) CHECK_NOT_IN_PLACE(4, recvbuf) if(sendbuf != MPI_IN_PLACE){ CHECK_COUNT(2, sendcount) @@ -238,6 +243,8 @@ int PMPI_Iallgather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, v } CHECK_TYPE(6, recvtype) CHECK_COUNT(5, recvcount) + CHECK_BUFFER(1, sendbuf, sendcount, sendtype) + CHECK_BUFFER(4, recvbuf, recvcount, recvtype) CHECK_REQUEST(8) if (sendbuf == MPI_IN_PLACE) { @@ -280,20 +287,23 @@ int PMPI_Iallgatherv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request) { CHECK_COMM(8) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) int rank = comm->rank(); - CHECK_BUFFER(1, sendbuf, sendcount) if(sendbuf != MPI_IN_PLACE) CHECK_TYPE(3, sendtype) CHECK_TYPE(6, recvtype) CHECK_NULL(5, MPI_ERR_COUNT, recvcounts) CHECK_NULL(6, MPI_ERR_ARG, displs) - if(sendbuf != MPI_IN_PLACE) + if(sendbuf != MPI_IN_PLACE){ CHECK_COUNT(2, sendcount) + CHECK_BUFFER(1, sendbuf, sendcount, sendtype) + } CHECK_REQUEST(9) CHECK_NOT_IN_PLACE(4, recvbuf) for (int i = 0; i < comm->size(); i++) { CHECK_COUNT(5, recvcounts[i]) - CHECK_BUFFER(4, recvbuf, recvcounts[i]) + CHECK_BUFFER(4, recvbuf, recvcounts[i], recvtype) } smpi_bench_end(); @@ -336,19 +346,21 @@ int PMPI_Iscatter(const void* sendbuf, int sendcount, MPI_Datatype sendtype, voi MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request* request) { CHECK_COMM(8) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) int rank = comm->rank(); if(rank == root){ CHECK_NOT_IN_PLACE_ROOT(1, sendbuf) - CHECK_BUFFER(1, sendbuf, sendcount) CHECK_COUNT(2, sendcount) CHECK_TYPE(3, sendtype) + CHECK_BUFFER(1, sendbuf, sendcount, sendtype) } else { CHECK_NOT_IN_PLACE_ROOT(4, recvbuf) } if(recvbuf != MPI_IN_PLACE){ - CHECK_BUFFER(4, recvbuf, recvcount) CHECK_COUNT(5, recvcount) CHECK_TYPE(6, recvtype) + CHECK_BUFFER(4, recvbuf, recvcount, recvtype) } CHECK_ROOT(8) CHECK_REQUEST(9) @@ -391,13 +403,15 @@ int PMPI_Scatterv(const void *sendbuf, const int *sendcounts, const int *displs, int PMPI_Iscatterv(const void* sendbuf, const int* sendcounts, const int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request* request) { + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) CHECK_COMM(9) int rank = comm->rank(); if(recvbuf != MPI_IN_PLACE){ CHECK_NOT_IN_PLACE_ROOT(1, sendbuf) - CHECK_BUFFER(4, recvbuf, recvcount) CHECK_COUNT(5, recvcount) CHECK_TYPE(7, recvtype) + CHECK_BUFFER(4, recvbuf, recvcount, recvtype) } CHECK_ROOT(9) CHECK_REQUEST(10) @@ -406,8 +420,8 @@ int PMPI_Iscatterv(const void* sendbuf, const int* sendcounts, const int* displs CHECK_NULL(3, MPI_ERR_ARG, displs) CHECK_TYPE(4, sendtype) for (int i = 0; i < comm->size(); i++){ - CHECK_BUFFER(1, sendbuf, sendcounts[i]) CHECK_COUNT(2, sendcounts[i]) + CHECK_BUFFER(1, sendbuf, sendcounts[i], sendtype) } if (recvbuf == MPI_IN_PLACE) { recvtype = sendtype; @@ -454,14 +468,16 @@ int PMPI_Reduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype data int PMPI_Ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm, MPI_Request* request) { CHECK_COMM(7) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) int rank = comm->rank(); - CHECK_BUFFER(1, sendbuf, count) + CHECK_TYPE(4, datatype) + CHECK_COUNT(3, count) + CHECK_BUFFER(1, sendbuf, count, datatype) if(rank == root){ CHECK_NOT_IN_PLACE(2, recvbuf) - CHECK_BUFFER(5, recvbuf, count) + CHECK_BUFFER(5, recvbuf, count, datatype) } - CHECK_TYPE(4, datatype) - CHECK_COUNT(3, count) CHECK_OP(5, op, datatype) CHECK_ROOT(7) CHECK_REQUEST(8) @@ -485,10 +501,12 @@ int PMPI_Ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype dat int PMPI_Reduce_local(const void* inbuf, void* inoutbuf, int count, MPI_Datatype datatype, MPI_Op op) { - CHECK_BUFFER(1, inbuf, count) - CHECK_BUFFER(2, inoutbuf, count) + SET_BUF1(inbuf) + SET_BUF2(inoutbuf) CHECK_TYPE(4, datatype) CHECK_COUNT(3, count) + CHECK_BUFFER(1, inbuf, count, datatype) + CHECK_BUFFER(2, inoutbuf, count, datatype) CHECK_OP(5, op, datatype) smpi_bench_end(); @@ -505,14 +523,16 @@ int PMPI_Allreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype d int PMPI_Iallreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, MPI_Request *request) { CHECK_COMM(6) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) int rank = comm->rank(); - CHECK_BUFFER(1, sendbuf, count) - CHECK_BUFFER(2, recvbuf, count) CHECK_NOT_IN_PLACE(2, recvbuf) CHECK_TYPE(4, datatype) + CHECK_OP(5, op, datatype) CHECK_COUNT(3, count) + CHECK_BUFFER(1, sendbuf, count, datatype) + CHECK_BUFFER(2, recvbuf, count, datatype) CHECK_REQUEST(7) - CHECK_OP(5, op, datatype) smpi_bench_end(); std::vector tmp_sendbuf; @@ -543,10 +563,12 @@ int PMPI_Scan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype dataty int PMPI_Iscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, MPI_Request* request) { CHECK_COMM(6) - CHECK_BUFFER(1,sendbuf,count) - CHECK_BUFFER(2,recvbuf,count) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) CHECK_TYPE(4, datatype) CHECK_COUNT(3, count) + CHECK_BUFFER(1,sendbuf,count, datatype) + CHECK_BUFFER(2,recvbuf,count, datatype) CHECK_REQUEST(7) CHECK_OP(5, op, datatype) @@ -578,10 +600,12 @@ int PMPI_Exscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype data int PMPI_Iexscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, MPI_Request* request){ CHECK_COMM(6) - CHECK_BUFFER(1, sendbuf, count) - CHECK_BUFFER(2, recvbuf, count) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) CHECK_TYPE(4, datatype) CHECK_COUNT(3, count) + CHECK_BUFFER(1, sendbuf, count, datatype) + CHECK_BUFFER(2, recvbuf, count, datatype) CHECK_REQUEST(7) CHECK_OP(5, op, datatype) @@ -614,6 +638,8 @@ int PMPI_Reduce_scatter(const void *sendbuf, void *recvbuf, const int *recvcount int PMPI_Ireduce_scatter(const void *sendbuf, void *recvbuf, const int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, MPI_Request *request) { CHECK_COMM(6) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) int rank = comm->rank(); CHECK_NOT_IN_PLACE(2, recvbuf) CHECK_TYPE(4, datatype) @@ -622,8 +648,8 @@ int PMPI_Ireduce_scatter(const void *sendbuf, void *recvbuf, const int *recvcoun CHECK_OP(5, op, datatype) for (int i = 0; i < comm->size(); i++) { CHECK_COUNT(3, recvcounts[i]) - CHECK_BUFFER(1, sendbuf, recvcounts[i]) - CHECK_BUFFER(2, recvbuf, recvcounts[i]) + CHECK_BUFFER(1, sendbuf, recvcounts[i], datatype) + CHECK_BUFFER(2, recvbuf, recvcounts[i], datatype) } smpi_bench_end(); @@ -664,10 +690,12 @@ int PMPI_Ireduce_scatter_block(const void* sendbuf, void* recvbuf, int recvcount MPI_Comm comm, MPI_Request* request) { CHECK_COMM(6) - CHECK_BUFFER(1, sendbuf, recvcount) - CHECK_BUFFER(2, recvbuf, recvcount) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) CHECK_TYPE(4, datatype) CHECK_COUNT(3, recvcount) + CHECK_BUFFER(1, sendbuf, recvcount, datatype) + CHECK_BUFFER(2, recvbuf, recvcount, datatype) CHECK_REQUEST(7) CHECK_OP(5, op, datatype) @@ -707,15 +735,17 @@ int PMPI_Ialltoall(const void* sendbuf, int sendcount, MPI_Datatype sendtype, vo MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request) { CHECK_COMM(7) - CHECK_BUFFER(1, sendbuf, sendcount) - CHECK_BUFFER(4, recvbuf, recvcount) - if(sendbuf != MPI_IN_PLACE) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) + if(sendbuf != MPI_IN_PLACE){ CHECK_TYPE(3, sendtype) + CHECK_COUNT(2, sendcount) + CHECK_BUFFER(1, sendbuf, sendcount, sendtype) + } CHECK_TYPE(6, recvtype) CHECK_COUNT(5, recvcount) - if(sendbuf != MPI_IN_PLACE) - CHECK_COUNT(2, sendcount) CHECK_COUNT(5, recvcount) + CHECK_BUFFER(4, recvbuf, recvcount, recvtype) CHECK_REQUEST(8) int pid = simgrid::s4u::this_actor::get_pid(); @@ -766,6 +796,8 @@ int PMPI_Ialltoallv(const void* sendbuf, const int* sendcounts, const int* sendd const int* recvcounts, const int* recvdispls, MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request) { CHECK_COMM(9) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) if(sendbuf != MPI_IN_PLACE){ CHECK_NULL(2, MPI_ERR_COUNT, sendcounts) CHECK_NULL(3, MPI_ERR_ARG, senddispls) @@ -780,10 +812,10 @@ int PMPI_Ialltoallv(const void* sendbuf, const int* sendcounts, const int* sendd int size = comm->size(); for (int i = 0; i < size; i++) { if(sendbuf != MPI_IN_PLACE){ - CHECK_BUFFER(1, sendbuf, sendcounts[i]) + CHECK_BUFFER(1, sendbuf, sendcounts[i], sendtype) CHECK_COUNT(2, sendcounts[i]) } - CHECK_BUFFER(5, recvbuf, recvcounts[i]) + CHECK_BUFFER(5, recvbuf, recvcounts[i], recvtype) CHECK_COUNT(6, recvcounts[i]) } @@ -859,6 +891,8 @@ int PMPI_Ialltoallw(const void* sendbuf, const int* sendcounts, const int* sendd const int* recvcounts, const int* recvdispls, const MPI_Datatype* recvtypes, MPI_Comm comm, MPI_Request* request) { CHECK_COMM(9) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) if(sendbuf != MPI_IN_PLACE){ CHECK_NULL(2, MPI_ERR_COUNT, sendcounts) CHECK_NULL(3, MPI_ERR_ARG, senddispls) @@ -872,13 +906,13 @@ int PMPI_Ialltoallw(const void* sendbuf, const int* sendcounts, const int* sendd int size = comm->size(); for (int i = 0; i < size; i++) { if(sendbuf != MPI_IN_PLACE){ - CHECK_BUFFER(1, sendbuf, sendcounts[i]) CHECK_COUNT(2, sendcounts[i]) CHECK_TYPE(4, sendtypes[i]) + CHECK_BUFFER(1, sendbuf, sendcounts[i], sendtypes[i]) } - CHECK_BUFFER(5, recvbuf, recvcounts[i]) CHECK_COUNT(6, recvcounts[i]) CHECK_TYPE(8, recvtypes[i]) + CHECK_BUFFER(5, recvbuf, recvcounts[i], recvtypes[i]) } smpi_bench_end(); diff --git a/src/smpi/bindings/smpi_pmpi_file.cpp b/src/smpi/bindings/smpi_pmpi_file.cpp index bda92271c8..371f562acd 100644 --- a/src/smpi/bindings/smpi_pmpi_file.cpp +++ b/src/smpi/bindings/smpi_pmpi_file.cpp @@ -23,16 +23,16 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi); #define CHECK_FILE_INPUTS \ CHECK_FILE(1, fh) \ - CHECK_BUFFER(2, buf, count) \ CHECK_COUNT(3, count) \ CHECK_TYPE(4, datatype) \ + CHECK_BUFFER(2, buf, count, datatype) \ #define CHECK_FILE_INPUT_OFFSET \ CHECK_FILE(1, fh) \ - CHECK_BUFFER(2, buf, count) \ CHECK_OFFSET(3, offset) \ CHECK_COUNT(4, count) \ CHECK_TYPE(5, datatype) \ + CHECK_BUFFER(2, buf, count, datatype) \ extern MPI_Errhandler SMPI_default_File_Errhandler; diff --git a/src/smpi/bindings/smpi_pmpi_request.cpp b/src/smpi/bindings/smpi_pmpi_request.cpp index 6447f78d45..e75d904147 100644 --- a/src/smpi/bindings/smpi_pmpi_request.cpp +++ b/src/smpi/bindings/smpi_pmpi_request.cpp @@ -19,9 +19,10 @@ static int getPid(MPI_Comm comm, int id) } #define CHECK_SEND_INPUTS\ - CHECK_BUFFER(1, buf, count)\ + SET_BUF1(buf)\ CHECK_COUNT(2, count)\ CHECK_TYPE(3, datatype)\ + CHECK_BUFFER(1, buf, count, datatype)\ CHECK_COMM(6)\ if(dst!= MPI_PROC_NULL)\ CHECK_RANK(4, dst, comm)\ @@ -33,11 +34,12 @@ static int getPid(MPI_Comm comm, int id) CHECK_SEND_INPUTS #define CHECK_IRECV_INPUTS\ + SET_BUF1(buf)\ CHECK_REQUEST(7)\ *request = MPI_REQUEST_NULL;\ - CHECK_BUFFER(1, buf, count)\ CHECK_COUNT(2, count)\ CHECK_TYPE(3, datatype)\ + CHECK_BUFFER(1, buf, count, datatype)\ CHECK_COMM(6)\ if(src!=MPI_ANY_SOURCE && src!=MPI_PROC_NULL)\ CHECK_RANK(4, src, comm)\ @@ -237,10 +239,10 @@ int PMPI_Issend(const void* buf, int count, MPI_Datatype datatype, int dst, int int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status) { int retval = 0; - - CHECK_BUFFER(1, buf, count) + SET_BUF1(buf) CHECK_COUNT(2, count) CHECK_TYPE(3, datatype) + CHECK_BUFFER(1, buf, count, datatype) CHECK_TAG(5, tag) CHECK_COMM(6) @@ -395,13 +397,15 @@ int PMPI_Sendrecv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, int int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status* status) { int retval = 0; - CHECK_BUFFER(1, sendbuf, sendcount) + SET_BUF1(sendbuf) + SET_BUF2(recvbuf) CHECK_COUNT(2, sendcount) CHECK_TYPE(3, sendtype) CHECK_TAG(5, sendtag) - CHECK_BUFFER(6, recvbuf, recvcount) CHECK_COUNT(7, recvcount) CHECK_TYPE(8, recvtype) + CHECK_BUFFER(1, sendbuf, sendcount, sendtype) + CHECK_BUFFER(6, recvbuf, recvcount, recvtype) CHECK_TAG(10, recvtag) CHECK_COMM(11) smpi_bench_end(); @@ -453,9 +457,10 @@ int PMPI_Sendrecv_replace(void* buf, int count, MPI_Datatype datatype, int dst, MPI_Comm comm, MPI_Status* status) { int retval = 0; - CHECK_BUFFER(1, buf, count) + SET_BUF1(buf) CHECK_COUNT(2, count) CHECK_TYPE(3, datatype) + CHECK_BUFFER(1, buf, count, datatype) int size = datatype->get_extent() * count; xbt_assert(size > 0); diff --git a/src/smpi/bindings/smpi_pmpi_type.cpp b/src/smpi/bindings/smpi_pmpi_type.cpp index 04208cb9c4..44de64ec9d 100644 --- a/src/smpi/bindings/smpi_pmpi_type.cpp +++ b/src/smpi/bindings/smpi_pmpi_type.cpp @@ -324,24 +324,28 @@ int PMPI_Type_free_keyval(int* keyval) { return simgrid::smpi::Keyval::keyval_free(keyval); } -int PMPI_Unpack(const void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) { - CHECK_NEGATIVE(2, MPI_ERR_COUNT, incount) +int PMPI_Unpack(const void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) { + SET_BUF1(inbuf) + SET_BUF2(outbuf) + CHECK_COMM(7) + CHECK_NEGATIVE(2, MPI_ERR_COUNT, insize) CHECK_NEGATIVE(5, MPI_ERR_COUNT, outcount) - CHECK_BUFFER(1, inbuf, incount) - CHECK_BUFFER(4, outbuf, outcount) CHECK_TYPE(6, type) - CHECK_COMM(7) - return type->unpack(inbuf, incount, position, outbuf,outcount, comm); + CHECK_BUFFER2(1, inbuf, outcount) + CHECK_BUFFER2(4, outbuf, outcount) + return type->unpack(inbuf, insize, position, outbuf,outcount, comm); } -int PMPI_Pack(const void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) { +int PMPI_Pack(const void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outsize, int* position, MPI_Comm comm) { + SET_BUF1(inbuf) + SET_BUF2(outbuf) + CHECK_COMM(7) CHECK_NEGATIVE(2, MPI_ERR_COUNT, incount) - CHECK_NEGATIVE(5, MPI_ERR_COUNT, outcount) - CHECK_BUFFER(1, inbuf, incount) - CHECK_BUFFER(4, outbuf, outcount) + CHECK_NEGATIVE(5, MPI_ERR_COUNT, outsize) CHECK_TYPE(6, type) - CHECK_COMM(7) - return type->pack(inbuf == MPI_BOTTOM ? nullptr : inbuf, incount, outbuf, outcount, position, comm); + CHECK_BUFFER2(1, inbuf, incount) + CHECK_BUFFER2(4, outbuf, incount) + return type->pack(inbuf == MPI_BOTTOM ? nullptr : inbuf, incount, outbuf, outsize, position, comm); } int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) { diff --git a/src/smpi/bindings/smpi_pmpi_win.cpp b/src/smpi/bindings/smpi_pmpi_win.cpp index deae860512..64bc6c00a6 100644 --- a/src/smpi/bindings/smpi_pmpi_win.cpp +++ b/src/smpi/bindings/smpi_pmpi_win.cpp @@ -14,9 +14,9 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi); #define CHECK_RMA\ - CHECK_BUFFER(1, origin_addr, origin_count)\ CHECK_COUNT(2, origin_count)\ CHECK_TYPE(3, origin_datatype)\ + CHECK_BUFFER(1, origin_addr, origin_count, origin_datatype)\ CHECK_PROC_RMA(4, target_rank, win)\ CHECK_COUNT(6, target_count)\ CHECK_TYPE(7, target_datatype) @@ -337,14 +337,14 @@ int PMPI_Raccumulate(const void *origin_addr, int origin_count, MPI_Datatype ori int PMPI_Get_accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, void *result_addr, int result_count, MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){ - if (op != MPI_NO_OP) - CHECK_BUFFER(1, origin_addr, origin_count) CHECK_COUNT(2, origin_count) if(origin_count>0) CHECK_TYPE(3, origin_datatype) - CHECK_BUFFER(4, result_addr, result_count) + if (op != MPI_NO_OP) + CHECK_BUFFER(1, origin_addr, origin_count, origin_datatype) CHECK_COUNT(5, result_count) CHECK_TYPE(6, result_datatype) + CHECK_BUFFER(4, result_addr, result_count, result_datatype) CHECK_WIN(12, win) CHECK_PROC_RMA(7, target_rank, win) CHECK_COUNT(9, target_count) @@ -380,12 +380,12 @@ int result_count, MPI_Datatype result_datatype, int target_rank, MPI_Aint target MPI_Datatype target_datatype, MPI_Op op, MPI_Win win, MPI_Request* request){ if(target_rank==MPI_PROC_NULL) *request = MPI_REQUEST_NULL; - CHECK_BUFFER(1, origin_addr, origin_count) CHECK_COUNT(2, origin_count) CHECK_TYPE(3, origin_datatype) - CHECK_BUFFER(4, result_addr, result_count) + CHECK_BUFFER(1, origin_addr, origin_count, origin_datatype) CHECK_COUNT(5, result_count) CHECK_TYPE(6, result_datatype) + CHECK_BUFFER(4, result_addr, result_count, result_datatype) CHECK_WIN(12, win) CHECK_PROC_RMA(7, target_rank, win) CHECK_COUNT(9, target_count) diff --git a/src/smpi/include/private.hpp b/src/smpi/include/private.hpp index da075e9d62..8087aa3f67 100644 --- a/src/smpi/include/private.hpp +++ b/src/smpi/include/private.hpp @@ -110,6 +110,7 @@ XBT_PRIVATE bool smpi_cfg_trace_call_use_absolute_path(); XBT_PRIVATE std::string smpi_cfg_comp_adjustment_file(); XBT_PRIVATE std::string smpi_cfg_papi_events_file(); XBT_PRIVATE double smpi_cfg_auto_shared_malloc_thresh(); +XBT_PRIVATE bool smpi_cfg_display_alloc(); // utilities extern XBT_PRIVATE char* smpi_data_exe_start; // start of the data+bss segment of the executable @@ -575,10 +576,21 @@ XBT_PRIVATE void private_execute_flops(double flops); simgrid::smpi::utils::set_current_handle(*request);\ }\ } +#define SET_BUF1(buf)\ + simgrid::smpi::utils::set_current_buffer(1, _XBT_STRINGIFY(buf), buf); +#define SET_BUF2(buf)\ + simgrid::smpi::utils::set_current_buffer(2, _XBT_STRINGIFY(buf), buf); -#define CHECK_BUFFER(num,buf,count)\ - CHECK_ARGS((buf) == nullptr && (count) > 0, MPI_ERR_BUFFER,\ - "%s: param %d %s cannot be NULL if %s > 0",__func__, (num), _XBT_STRINGIFY(buf), _XBT_STRINGIFY(count)) +#define CHECK_BUFFER2(num,buf,count)\ + CHECK_ARGS((buf) == nullptr && (count) > 0, MPI_ERR_BUFFER,\ + "%s: param %d %s cannot be NULL if %s > 0",__func__, (num), _XBT_STRINGIFY(buf), _XBT_STRINGIFY(count))\ + +#define CHECK_BUFFER(num,buf,count,datatype)\ + {\ + CHECK_BUFFER2(num,buf,count)\ + CHECK_ARGS( simgrid::smpi::utils::get_buffer_size(buf) < (size_t)(count*datatype->get_extent()), MPI_ERR_BUFFER,\ + "%s: param %d message size %ld exceeds buffer %s size %zu",__func__, (num), count*datatype->get_extent(), _XBT_STRINGIFY(buf), simgrid::smpi::utils::get_buffer_size(buf))\ + } #define CHECK_COUNT(num, count)\ CHECK_NEGATIVE((num), MPI_ERR_COUNT, (count)) diff --git a/src/smpi/mpi/smpi_win.cpp b/src/smpi/mpi/smpi_win.cpp index 4d32732c80..cfee3d94bd 100644 --- a/src/smpi/mpi/smpi_win.cpp +++ b/src/smpi/mpi/smpi_win.cpp @@ -18,6 +18,23 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_rma, smpi, "Logging specific to SMPI (RMA operations)"); +#define CHECK_RMA_REMOTE_WIN(fun, win)\ + if(target_count*target_datatype->get_extent()>win->size_){\ + XBT_WARN("%s: Trying to move %zd, which exceeds the window size on target process %d : %zd - Bailing out.",\ + fun, target_count*target_datatype->get_extent(), target_rank, win->size_);\ + simgrid::smpi::utils::set_current_buffer(1,"win_base",win->base_);\ + return MPI_ERR_RMA_RANGE;\ + } + +#define CHECK_WIN_LOCKED(win)\ + if(opened_==0){ /*check that post/start has been done*/\ + int locked=0;\ + for (auto const& it : win->lockers_)\ + if (it == comm_->rank())\ + locked = 1;\ + if(locked != 1)\ + return MPI_ERR_WIN;\ + } namespace simgrid{ namespace smpi{ @@ -216,11 +233,7 @@ int Win::put(const void *origin_addr, int origin_count, MPI_Datatype origin_data return MPI_ERR_WIN; } - if(target_count*target_datatype->get_extent()>recv_win->size_){ - XBT_WARN("MPI_Put: Trying to put %zd, which is more than the window size on target process %d : %zd - Bailing out.", - target_count*target_datatype->get_extent(), target_rank, recv_win->size_); - return MPI_ERR_RMA_RANGE; - } + CHECK_RMA_REMOTE_WIN("MPI_Put", recv_win) void* recv_addr = static_cast(recv_win->base_) + target_disp * recv_win->disp_unit_; @@ -269,21 +282,8 @@ int Win::get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, //get sender pointer Win* send_win = connected_wins_[target_rank]; - if(opened_==0){//check that post/start has been done - // no fence or start .. lock ok ? - int locked=0; - for (auto const& it : send_win->lockers_) - if (it == comm_->rank()) - locked = 1; - if(locked != 1) - return MPI_ERR_WIN; - } - - if(target_count*target_datatype->get_extent()>send_win->size_){ - XBT_WARN("MPI_Get: Trying to get %zd, which is more than the window size on target process %d : %zd - Bailing out.", - target_count*target_datatype->get_extent(), target_rank, send_win->size_); - return MPI_ERR_RMA_RANGE; - } + CHECK_WIN_LOCKED(send_win) + CHECK_RMA_REMOTE_WIN("MPI_Get", send_win) const void* send_addr = static_cast(static_cast(send_win->base_) + target_disp * send_win->disp_unit_); XBT_DEBUG("Entering MPI_Get from %d", target_rank); @@ -331,22 +331,9 @@ int Win::accumulate(const void *origin_addr, int origin_count, MPI_Datatype orig //get receiver pointer Win* recv_win = connected_wins_[target_rank]; - if(opened_==0){//check that post/start has been done - // no fence or start .. lock ok ? - int locked=0; - for (auto const& it : recv_win->lockers_) - if (it == comm_->rank()) - locked = 1; - if(locked != 1) - return MPI_ERR_WIN; - } //FIXME: local version - - if(target_count*target_datatype->get_extent()>recv_win->size_){ - XBT_WARN("MPI_Accumulate: Trying to accumulate %zd, which is more than the window size on target process %d : %zd - Bailing out.", - target_count*target_datatype->get_extent(), target_rank, recv_win->size_); - return MPI_ERR_RMA_RANGE; - } + CHECK_WIN_LOCKED(recv_win) + CHECK_RMA_REMOTE_WIN("MPI_Accumulate", recv_win) void* recv_addr = static_cast(recv_win->base_) + target_disp * recv_win->disp_unit_; XBT_DEBUG("Entering MPI_Accumulate to %d", target_rank); @@ -390,22 +377,8 @@ int Win::get_accumulate(const void* origin_addr, int origin_count, MPI_Datatype //get sender pointer const Win* send_win = connected_wins_[target_rank]; - if(opened_==0){//check that post/start has been done - // no fence or start .. lock ok ? - int locked=0; - for (auto const& it : send_win->lockers_) - if (it == comm_->rank()) - locked = 1; - if(locked != 1) - return MPI_ERR_WIN; - } - - if(target_count*target_datatype->get_extent()>send_win->size_){ - XBT_WARN("MPI_Get_accumulate: Trying to get_accumulate %zd, which is more than the window size on target process %d : %zd - Bailing out.", - target_count*target_datatype->get_extent(), target_rank, send_win->size_); - return MPI_ERR_RMA_RANGE; - } - + CHECK_WIN_LOCKED(send_win) + CHECK_RMA_REMOTE_WIN("MPI_Get_Accumulate", send_win) XBT_DEBUG("Entering MPI_Get_accumulate from %d", target_rank); //need to be sure ops are correctly ordered, so finish request here ? slow. @@ -430,15 +403,7 @@ int Win::compare_and_swap(const void* origin_addr, const void* compare_addr, voi //get sender pointer const Win* send_win = connected_wins_[target_rank]; - if(opened_==0){//check that post/start has been done - // no fence or start .. lock ok ? - int locked=0; - for (auto const& it : send_win->lockers_) - if (it == comm_->rank()) - locked = 1; - if(locked != 1) - return MPI_ERR_WIN; - } + CHECK_WIN_LOCKED(send_win) XBT_DEBUG("Entering MPI_Compare_and_swap with %d", target_rank); MPI_Request req = MPI_REQUEST_NULL; -- 2.20.1