From patchwork Wed Jun 19 00:05:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13703197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7DBBC2BA1A for ; Wed, 19 Jun 2024 00:05:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94CFE6B02B5; Tue, 18 Jun 2024 20:05:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F8D86B02BC; Tue, 18 Jun 2024 20:05:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 724416B02B8; Tue, 18 Jun 2024 20:05:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 552BE6B02B2 for ; Tue, 18 Jun 2024 20:05:31 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 13CB6120BC8 for ; Wed, 19 Jun 2024 00:05:31 +0000 (UTC) X-FDA: 82245694062.01.9320E3A Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf26.hostedemail.com (Postfix) with ESMTP id DAB18140007 for ; Wed, 19 Jun 2024 00:05:28 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=o2j3NCQE; spf=pass (imf26.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718755519; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iMkszGdm9ae/n7pRpO/rrT8MarQ3LgEe54I6kubPvLI=; b=zAwfjgaTuJpNLimm2qs3dpMm/XhsdaNdYRdrOvcrO8HlGoEFzYy/8Lhv9J2lpoUo1dLDQ+ g0czIDKvhAg5o6TRrN57b1XW9DK+ask9MfsMECKXvd79W7HUt89dn7/vjW9lRtrUb4ilGS K6Jbd3JEGAr/5qk6wuSFzzKYJLjrtqs= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=o2j3NCQE; spf=pass (imf26.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718755519; a=rsa-sha256; cv=none; b=M2aOt7zoodVlNKjuJqmLHbsZS5hTR8MZ0C2Sq3YB7D9TUFv0LRN9stDnWIE/1fxF11S+HF qfsooFJ21H9Vwl+d8/z1ttNOR5gFbz3R2w83CuqQo8VC21wjh8irOLSItqa5GVmBWX7D4J E7utbhey0QJmXVYq/rSt8LdZuY6l8qM= Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45ILb6Xo000504; Wed, 19 Jun 2024 00:05:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= iMkszGdm9ae/n7pRpO/rrT8MarQ3LgEe54I6kubPvLI=; b=o2j3NCQEJTFU2hZA IcfJBRdS+w2hLNTSnVEQqnCk6AXpZRPDzzyjWU3587KuuQzZLw5I/0tOLUNVu6UP Rs6j0xFWBjkFJmhUD+PeP0g9pvohDo5Y8d2hN4+BOXp6oLp/9rFH5UWggdClLz25 rRhoaL7pj6CoQXuGDGoeGiDlQlUrTPKq5n4fqNiF4XWg7fYW2lZIs0xabEKlei/F fubw4xm7gCPQsE4bGTlJ+UpHrkc22hnsqi5ae6AcKEp8m+Dmg7hgq2ReUMYGqtoV N2eCzPir57qdth9XiRT9nDGlGmmenoIIk2FhV/utsVba60mRmieP4CfYuSeG0BnC WXrfVg== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yujag07ba-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 00:05:19 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA03.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 45J05IcW029972 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 00:05:18 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Tue, 18 Jun 2024 17:05:18 -0700 From: Elliot Berman Date: Tue, 18 Jun 2024 17:05:11 -0700 Subject: [PATCH RFC 5/5] mm/gup_test: Verify GUP grabs same pages twice MIME-Version: 1.0 Message-ID: <20240618-exclusive-gup-v1-5-30472a19c5d1@quicinc.com> References: <20240618-exclusive-gup-v1-0-30472a19c5d1@quicinc.com> In-Reply-To: <20240618-exclusive-gup-v1-0-30472a19c5d1@quicinc.com> To: Andrew Morton , Shuah Khan , David Hildenbrand , Matthew Wilcox , CC: , , , , , , Elliot Berman X-Mailer: b4 0.13.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: unhDqPMZarSEVc31r4x6VcJKNGdRtYup X-Proofpoint-ORIG-GUID: unhDqPMZarSEVc31r4x6VcJKNGdRtYup X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-18_06,2024-06-17_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 impostorscore=0 suspectscore=0 adultscore=0 spamscore=0 malwarescore=0 phishscore=0 mlxlogscore=880 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406180176 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DAB18140007 X-Stat-Signature: bsrsxer9ddwpuwd38f6xoteqkfsb6yqg X-Rspam-User: X-HE-Tag: 1718755528-376017 X-HE-Meta: U2FsdGVkX19RiLdn9nSSsfVqIS9FEPPgcPO8igNkqxftfmXYrRMzWeAq96nRHNuZd7mcJ0lJcKz1kjeRiqYX8HBJeTYpH2saLODTks62HQEzopgmHHODo+3J4VmKTmKSkIg/o6ciJPVCFJFfvcl8IPBzPTJX5lcMuKHHJuWtG8Hy8P0UuZW67dG9WN9r013AZLfTq0Oggs22iUKqZGzoku6VdeyonKUcyKaK37WBI+1TK4NEdzUQHtVtaA0JcYbYN24teVDrkZ77VOWxh4oc1X+whyGPfI+kPH0b/2Vrat37LSIqDNSlzj5L4kzJkcZmtqKW2VjRlcd92WmeAAMKa2qX5cdbB7Pt9KhbxmswD/vAcbSCRhPSu9LKwZXT/eqKbBdYR6h0yvcT6u6NRgPmYJqrj33ShngJjyg2SGzzTzp/cUoQr5GXDZjsS2hu4ExdzCTX60v0v4xZnaxTu5KJYiD3F6RNDVqn7j2gtM1V3i5L4k+7IOx8XTQK1slpEa3d+ttt6pxIAk0MXKUg7+czOeiezDedym0yWw/X5o2llm5R7UIrCPxAYu3BeTg4tuyIW/NblTaSuHt8jOq+vEuw4dDzMgb6ZRGt9uj9HMvh3d/DNOSyyWPxVjB4ybf1Qy10i6afUAmQSCZf5nmthTa4z13AkPz/729o43H3QbG8+8/zSTu9rFqopgLntCai15tMFzc9dyEuTR2zo1afWgKzWe0oqiaY4hnyAIA/x48oqLn9BurzWGyXdmW7Pr/dUhbwn20Ss0OqoFFJoAtLohbLuXfmFVPikPgB524EPfqQFqNehEL/2iwPaPnvDwLw4HVlGcyHfUNkhFXZpgjvBSq33M0AfpA/v6zKWbu/ohNacN++y8W2rlEMeO67a6fmzQeFaEbodHdgXQ4ZVcKXB1F+eXXbxWL+6itrHhj8VR4NUzr058gg59r3BQKbl28wsztHAqbk/yIfI+WHuKwa4JL lYs+W/1T uoED1xJCaxSw/Qf9169YtsR9y4M0+uDdyRgXVCbq2vMFCTREDmjKhqM2UeHRjPjpmUzdCyNgp5QN2HxME45WBnXVL5NNwMdWCIZjTR4pniPtD7ffzJx/WAjtCJsbEMlWuoss8YZnGZofX4oV9EoeFkae2xAoTJ9nscesnKVYpvoL2xwC+kk/KQ1IBsL62Au24XLyj81BPRO4UEWHRhXgbEun8GB7dk21F6WKqxQCVw8wgBJsVC8eXYZRLwJSZgt3mRKEliylZYo/zVKKTTWNRKfF1oqF+mgTz7PRRDi6aIbnL+9YWn2mytcDu3JT20fcdg6u5e19bdLY8Evtta3l2MJdsdgOf96vDALB6K7akFYWiT59T8AlWwcwyhBIRma2CytRF X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: GUP'ing pages should get the same pages, test it. In case of FOLL_EXCLUSIVE, the second pin should fail to get any pages. Note: this change ought to be refactored to pull out the GUP'ing bits that's duplicated between the original and the second GUP. Signed-off-by: Elliot Berman --- mm/gup_test.c | 86 +++++++++++++++++++++++++++++++++++ mm/gup_test.h | 1 + tools/testing/selftests/mm/gup_test.c | 5 +- 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/mm/gup_test.c b/mm/gup_test.c index 9c6b8c93e44a7..28cc422b60b78 100644 --- a/mm/gup_test.c +++ b/mm/gup_test.c @@ -86,6 +86,89 @@ static void verify_exclusive_pinned(unsigned int gup_flags, struct page **pages, } } +static int verify_gup_twice(unsigned int cmd, struct gup_test *gup, + struct page **expected_pages, + unsigned long expected_nr_pages) +{ + unsigned long i, nr_pages, addr, next; + long nr; + struct page **pages __free(kfree) = NULL; + int ret = 0; + + nr_pages = gup->size / PAGE_SIZE; + pages = kvcalloc(nr_pages, sizeof(void *), GFP_KERNEL); + if (!pages) + return -ENOMEM; + + i = 0; + nr = gup->nr_pages_per_call; + for (addr = gup->addr; addr < gup->addr + gup->size; addr = next) { + if (nr != gup->nr_pages_per_call) + break; + + next = addr + nr * PAGE_SIZE; + if (next > gup->addr + gup->size) { + next = gup->addr + gup->size; + nr = (next - addr) / PAGE_SIZE; + } + + switch (cmd) { + case GUP_FAST_BENCHMARK: + nr = get_user_pages_fast(addr, nr, gup->gup_flags, + pages + i); + break; + case GUP_BASIC_TEST: + nr = get_user_pages(addr, nr, gup->gup_flags, pages + i); + break; + case PIN_FAST_BENCHMARK: + nr = pin_user_pages_fast(addr, nr, gup->gup_flags, + pages + i); + break; + case PIN_BASIC_TEST: + nr = pin_user_pages(addr, nr, gup->gup_flags, pages + i); + break; + case PIN_LONGTERM_BENCHMARK: + nr = pin_user_pages(addr, nr, + gup->gup_flags | FOLL_LONGTERM, + pages + i); + break; + default: + pr_err("cmd %d not supported for %s\n", cmd, __func__); + return -EINVAL; + } + + if (nr <= 0) + break; + i += nr; + } + + nr_pages = i; + + if (gup->gup_flags & FOLL_EXCLUSIVE) { + if (WARN(nr_pages, + "Able to acquire exclusive pin twice for %ld of %ld pages", + nr_pages, expected_nr_pages)) { + dump_page(pages[0], + "gup_test: verify_gup_twice() test"); + ret = -EIO; + } + } else if (nr_pages != expected_nr_pages) { + pr_err("%s: Expected %ld pages, got %ld\n", __func__, + expected_nr_pages, nr_pages); + ret = -EIO; + } else { + for (i = 0; i < nr_pages; i++) { + if (WARN(pages[i] != expected_pages[i], + "pages[%lu] mismatch\n", i)) + break; + } + } + + put_back_pages(cmd, pages, nr_pages, gup->test_flags); + + return ret; +} + static void dump_pages_test(struct gup_test *gup, struct page **pages, unsigned long nr_pages) { @@ -210,6 +293,9 @@ static int __gup_test_ioctl(unsigned int cmd, if (cmd == DUMP_USER_PAGES_TEST) dump_pages_test(gup, pages, nr_pages); + if (gup->test_flags & GUP_TEST_FLAG_GUP_TWICE) + ret = verify_gup_twice(cmd, gup, pages, nr_pages); + start_time = ktime_get(); put_back_pages(cmd, pages, nr_pages, gup->test_flags); diff --git a/mm/gup_test.h b/mm/gup_test.h index 5b37b54e8bea6..fcd41919b0159 100644 --- a/mm/gup_test.h +++ b/mm/gup_test.h @@ -17,6 +17,7 @@ #define GUP_TEST_MAX_PAGES_TO_DUMP 8 #define GUP_TEST_FLAG_DUMP_PAGES_USE_PIN 0x1 +#define GUP_TEST_FLAG_GUP_TWICE 0x2 struct gup_test { __u64 get_delta_usec; diff --git a/tools/testing/selftests/mm/gup_test.c b/tools/testing/selftests/mm/gup_test.c index bdeaac67ff9aa..b4b10c8338f80 100644 --- a/tools/testing/selftests/mm/gup_test.c +++ b/tools/testing/selftests/mm/gup_test.c @@ -98,7 +98,7 @@ int main(int argc, char **argv) pthread_t *tid; char *p; - while ((opt = getopt(argc, argv, "m:r:n:F:f:abcj:tTLUuwWSHpz")) != -1) { + while ((opt = getopt(argc, argv, "m:r:n:F:f:abcj:dtTLUuwWSHpz")) != -1) { switch (opt) { case 'a': cmd = PIN_FAST_BENCHMARK; @@ -172,6 +172,9 @@ int main(int argc, char **argv) /* fault pages in gup, do not fault in userland */ touch = 1; break; + case 'd': + gup.test_flags |= GUP_TEST_FLAG_GUP_TWICE; + break; default: ksft_exit_fail_msg("Wrong argument\n"); }