From patchwork Fri Dec 6 17:52:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13897540 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB5DBE77173 for ; Fri, 6 Dec 2024 17:52:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id:MIME-Version:Subject: Date:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=sIA37XHvZlntCS2OcEZYyu2Sb4L2kGPTfcPUFOaIiYk=; b=tbPNL2qL1mjQ9x rpgVuDv0asyg8xUqwLZma6SaBXjM+0rM5TfjvNalgUG8Q0cohjCWDsBDJXPfuTfUtva8+3ZhSVOG+ BddiAn/ygRFIpGTfKqcAEsUfBpv7R6/ZnRPfGXEV7t2XsRduDAcVerRylGtlWunXJzQcHZlYOrvpi bAtnKxTaP/tjiN+2DJsTYpjnLtnidNTgffYTUzB0z2tPQq94zPDAF0nwNzEr+8B8Q2C8gVLSosntH 85DgrqGnQePzIvHalZk/rngQdaoaPfrJ8V6S5MzNaY0A92LO+9zhfYWTZCEU1VvWDlHYas3v5mjmA 1LVrvoJHgS36iKpapLaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tJcV7-00000002OTe-2sTL; Fri, 06 Dec 2024 17:52:25 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tJcV5-00000002OTE-066L for linux-riscv@lists.infradead.org; Fri, 06 Dec 2024 17:52:24 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-21628b3fe7dso1178365ad.3 for ; Fri, 06 Dec 2024 09:52:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733507540; x=1734112340; darn=lists.infradead.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=t74r+A3G8A2DioiaE7k2dQqMFjTyp32lyeabaPRYOLc=; b=wwChnFJe1loiaGJqLoQL1kbf0CFVF82dU2h4Jg1gtxi88WhczJsoJsU4O5psJh/1P7 4HzsQm9/cJIr5DtmqOam+vR2gyugVw4LenjJadBj0O4mmtF3m9ftGIvtmjrbOdDZUlLJ TVVqQJ0qTIadlN07pHel6mR8KfmCXA3exVHkPf5CzPJsPUYyPbByGtr9RiAK7m7Z+TmR JFfFiZADBm0SbJRKVdv3oxd1hdaLsSM2ydjks4yI9TOraF+SCH9YLfpDczD10IYHurnk zoTWZbg9+Uu17tCL256XXyZlWLEbA2wYVtb5R3GxbpHfUfuk/KCBXvvpjGbGfci+TMnF 6qlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733507540; x=1734112340; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=t74r+A3G8A2DioiaE7k2dQqMFjTyp32lyeabaPRYOLc=; b=VfxvH6X06ONM005/sbfpgWRzt18rmjN9mw9qLRaEPQ5vT/Sj2mXf5BL3pUZwfAzE5g E+uYez8Myp4ASMXKJPQuURVOnJYcPp0mXceM2sxXsy7WDh5/Da7TgY4/GF4ZsquGHxj9 km55FWaHJy3zoAFd/MzXNNiJOHSBHqCBAT54ep3ww/n6VMs5VluuTUSL81HVKurjypPI aZqh9yuvkOu9FqyiN25y8cI/pjtpn3LgE7jn9VmllJDumPOO0S3J/jyMIttKOwik15hK /RZl7+fREAJHe8ve3c9hI3Yqr/tftf4hav+TwpRAFIzD2DdDMnLEeeyOzaXSa2pDunKB D4/w== X-Forwarded-Encrypted: i=1; AJvYcCVrvaNIdLcwIOSA7wiMo70FCNcCdvk4bJ/VkxoetYG2XplcKegNNrw67a0AutyIK7yViKlvVAf7CEgQhQ==@lists.infradead.org X-Gm-Message-State: AOJu0Yz3AsQZXqMZkBi80XRCUCNBWBuwEwNTCn0O/F5AURm0fir6fVJH mfQ16giURd9J/IEej8je6mO+2EegaHxRw/CQueW3FjLkQELmC4x9iVCeo2/U9sQ= X-Gm-Gg: ASbGncurQxohu14H39R558w+qZ4gobriIpiIEnE8orCIze2yArtLRI75WQyGQcUu8W5 Niw8a4MhIZMIi/45qErta5tk4mV8RFl4h+mGTVdFsHtdyzbT7vo7vfZCyDKwkI0DO0QBfbpYf9r Wyq7rW/3erEsg7zwWy+Yl+GKuT3lnL/R87vbGrPNWqSYzqiBJSskRCey5dvY23F6+9VshW5LJeU bQrTes8eKHVrXVV9tHGs6tb3KIAwjSAkG9WOGL16yX68PGG99W0qzzC8HFUf1+RCg== X-Google-Smtp-Source: AGHT+IHJY3+a/koaJNAgjd3cks/U/UAswsKw1upCByf2SIYnfguQrHFIStQdCoJiAXcWG1KzXuXRfg== X-Received: by 2002:a17:902:cecc:b0:215:b18d:ef with SMTP id d9443c01a7336-21614d4e548mr43127485ad.25.1733507539892; Fri, 06 Dec 2024 09:52:19 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-215f8f091fesm31464545ad.194.2024.12.06.09.52.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 09:52:19 -0800 (PST) From: Charlie Jenkins Date: Fri, 06 Dec 2024 09:52:11 -0800 Subject: [PATCH v5] riscv: selftests: Fix warnings pointer masking test MIME-Version: 1.0 Message-Id: <20241206-fix_warnings_pointer_masking_tests-v5-1-ed566c2f27e8@rivosinc.com> X-B4-Tracking: v=1; b=H4sIAMo5U2cC/5XNwW7DIBAE0F+JOJcKMIvtnvofVWRhsiSrKhCxF k0V+d9LcqqqHOrjjDRvboKxELJ4291EwUpMObUALzsRTj4dUdKhZWGUsdooKyNdpy9fEqUjT5d MacEynT1/tmJakBeW3eAU2tiBNaNo0KVgWz1OPvYtn4iXXL4fn1Xf20181VJL9BpH5yBg798L1 cyUwmvIZ3F/qGa7apqq56gCqBEiDE/U7rcK/1K7pkIww6zi6Kw6PFHtdtU2VYW+x7k3YAf3R13 X9Qcc1RmG2QEAAA== To: Shuah Khan , Paul Walmsley , Palmer Dabbelt , Samuel Holland , Andrew Jones , Alexandre Ghiti Cc: linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3302; i=charlie@rivosinc.com; h=from:subject:message-id; bh=wHElZ6pqb0iSr7hWzaw1Hkcd5+EIf3oGgJDHM5LJtKY=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ3qw5WnfF8acWToTNvwVzjh6/IRoUr4p30Q17/mnt2Y4i z86P/V+RykLgxgHg6yYIgvPtQbm1jv6ZUdFyybAzGFlAhnCwMUpABOpXc3I0HJaKCGA4+SsaGXr gzOO/z8lu0HcLq3kG8uhQMlPnwXqpRn+V0wy9V5u0n42cNmH3xl2xyY/aFn91TXqtvw1OUOfB0c auQA= X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241206_095223_061734_9690D3F4 X-CRM114-Status: GOOD ( 11.75 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org When compiling the pointer masking tests with -Wall this warning is present: pointer_masking.c: In function ‘test_tagged_addr_abi_sysctl’: pointer_masking.c:203:9: warning: ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 203 | pwrite(fd, &value, 1, 0); | ^~~~~~~~~~~~~~~~~~~~~~~~ pointer_masking.c:208:9: warning: ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 208 | pwrite(fd, &value, 1, 0); I came across this on riscv64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04). Fix this by checking that the number of bytes written equal the expected number of bytes written. Fixes: 7470b5afd150 ("riscv: selftests: Add a pointer masking test") Signed-off-by: Charlie Jenkins Reviewed-by: Andrew Jones --- Changes in v5: - No longer skip second pwrite if first one fails - Use wrapper function instead of goto (Drew) - Link to v4: https://lore.kernel.org/r/20241205-fix_warnings_pointer_masking_tests-v4-1-0c77eb725486@rivosinc.com Changes in v4: - Skip sysctl_enabled test if first pwrite failed - Link to v3: https://lore.kernel.org/r/20241205-fix_warnings_pointer_masking_tests-v3-1-5c28b0f9640d@rivosinc.com Changes in v3: - Fix sysctl enabled test case (Drew/Alex) - Move pwrite err condition into goto (Drew) - Link to v2: https://lore.kernel.org/r/20241204-fix_warnings_pointer_masking_tests-v2-1-1bf0c5095f58@rivosinc.com Changes in v2: - I had ret != 2 for testing, I changed it to be ret != 1. - Link to v1: https://lore.kernel.org/r/20241204-fix_warnings_pointer_masking_tests-v1-1-ea1e9665ce7a@rivosinc.com --- .../testing/selftests/riscv/abi/pointer_masking.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) --- base-commit: 40384c840ea1944d7c5a392e8975ed088ecf0b37 change-id: 20241204-fix_warnings_pointer_masking_tests-3860e4f35429 diff --git a/tools/testing/selftests/riscv/abi/pointer_masking.c b/tools/testing/selftests/riscv/abi/pointer_masking.c index dee41b7ee3e3..50c4d1bc7570 100644 --- a/tools/testing/selftests/riscv/abi/pointer_masking.c +++ b/tools/testing/selftests/riscv/abi/pointer_masking.c @@ -185,8 +185,20 @@ static void test_fork_exec(void) } } +static bool pwrite_wrapper(int fd, void *buf, size_t count, const char *msg) +{ + int ret = pwrite(fd, buf, count, 0); + + if (ret != count) { + ksft_perror(msg); + return false; + } + return true; +} + static void test_tagged_addr_abi_sysctl(void) { + char *err_pwrite_msg = "failed to write to /proc/sys/abi/tagged_addr_disabled\n"; char value; int fd; @@ -200,14 +212,12 @@ static void test_tagged_addr_abi_sysctl(void) } value = '1'; - pwrite(fd, &value, 1, 0); - ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == -EINVAL, - "sysctl disabled\n"); + if (!pwrite_wrapper(fd, &value, 1, "write '1'")) + ksft_test_result_fail(err_pwrite_msg); value = '0'; - pwrite(fd, &value, 1, 0); - ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == 0, - "sysctl enabled\n"); + if (!pwrite_wrapper(fd, &value, 1, "write '0'")) + ksft_test_result_fail(err_pwrite_msg); set_tagged_addr_ctrl(0, false);