From patchwork Thu Dec 12 07:01:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13904747 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 91C40E7717F for ; Thu, 12 Dec 2024 07:02:20 +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=mFPOZDJWsBpFOzekgjSWyWFKnVBRg+KKN/aSylAusZo=; b=Dkd7s+vtY9amfz 1Fh2Cr46FDAO7HmSLvuMIgAgZLkJfj31Ts2NY2EJDKLLg/UZ6CCc03GZLmxQjGg8WCXTD7c5hpkfr rultO+hHcP6gA8+VIEIj8WaI6dJjfQjhZj5d/m8OoFycDu3yk1iXQlK/KAkk8pPbVjJOm/68pYXzo fSdIfT5v//nAVavXxZESMHq7JBeB5Cc0pOWkECJO6uDXEsYL2KO8vZJ/jVhRaNFkjEKA/izvysDPj +ivUpv5ggy7gLVc/6xiyQbIDEUZjTgg0NQd2FaRRxKNn7mhTjgNahYLg/8J2F8OTjjvui2NsbAMyo Ek0LT15JDeckAhMEenSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tLdDB-0000000H6Ad-16u0; Thu, 12 Dec 2024 07:02:13 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tLdD8-0000000H69q-0kva for linux-riscv@lists.infradead.org; Thu, 12 Dec 2024 07:02:11 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-72739105e02so341651b3a.0 for ; Wed, 11 Dec 2024 23:02:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733986929; x=1734591729; 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=OGZhgzI92zZ53/39Sn1Oo9uqJ+TialabZU7b4n5pT6I=; b=yGBPdStbvoh1YF7PTFFiECVhCbdgjHJi6Unp5xsyOXMZvINgqZyUSxIAco+qyisvkz WsYNGXXzM7ZN/SE8QNHpcy3EjPxQjPTENtuKtG/mbLSYnLdRyrZWoXlpsHeEIqnBBJsO PJXqUEC4U+QCc5qT/NOXB0TdrIWM0uyyuEFB0eR/aSNYwKmWDUSNmWZTSU10ohkoDjl9 YQWx8ft1Pqjiv7rILskfIxRLdRx8q5/UuCd4xmPfRrbItjo+Hp/tJ8DkyQsbsBUFa8dJ PpjakE/MsnQk2F0C1s7tJv+SHyaLBaNSn9N4F8j14s+QTRfc9atX9DulAUpYGrEt72Tw Djvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733986929; x=1734591729; 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=OGZhgzI92zZ53/39Sn1Oo9uqJ+TialabZU7b4n5pT6I=; b=dh+1tN8w9Lcu3M+Wx1DX26NpLTWC0nBPr/WPn6MOs3X5mPIJcNcO88qQjKrKvnIgkm RGgF5cLt/vWzzMqgeWsakTI3jst+CewY8fHOqtHFQHcWI86d4fGR2F3+1eZTNuIBqAwG lBXfNDQxYDbgcx0fY0LSDu4uQvLJD32x83Iigva7T+3YvOSp/Mwti39MD7KFa7a9IIFt zvkDKlTVFVaaOG99yQmTi9nB1uxhfmfPPW8xL/+c/ZZdrC8+V/B5Ffi/4uwe3zMNe3M+ K+kNgTbgZPlHCnffQdr8Oi2ePFbPjNlx5YguceJYwkGl8o8MB96F8cdF0Gq9wxcfBDH0 ss9A== X-Forwarded-Encrypted: i=1; AJvYcCVBh9PL7a2QDtAiCmoijL53oJeCG3DShrLzE491dXzBkDgDNst6iykIv9oBLFhEVff9GRrr7/35lnaXZw==@lists.infradead.org X-Gm-Message-State: AOJu0YzaeOoZqhXF8gb5KaBBnQUUwJiuU0L6O8pfyJrMWeVRwhvbMzys YjIYWofw7jcSGQimBmh0wxD0eEO87ED/hhxwlTwmz4NBlQDuK1VT6+zxC3dvr+M= X-Gm-Gg: ASbGncsLObGvcZ8xXyLqp5l4DL/Z7ktF83FG9jRNDPFnS3Z+CXI2nqEPaC/sRKVTFjw M2zL+cC826HtFJjtk53l87KqWwD/lHpVXu0Ngct1kfNc2A/rolqCTuxoyElgsT8UJu1HE77hdNe fKxnIBqe0VBBb1gEPrBxOQ2S0jl1qbhy8GdzROhbdkKBdfHJwwUFkgtg5A3e65U3Viu3xkHDJw4 2L67YCzLE8NxHQjwRh2vD9CrdyfELlROqMkTAD+AD31Li2++0+wdzZMf5kH3AxaZCNBYtj2 X-Google-Smtp-Source: AGHT+IFVhoqBC+FHK0O0yj4L3ROsxkwQrItwr6XNYnjRPa8c45hGqnxiby8r0RoTiwqRnzYyUk6n5A== X-Received: by 2002:a05:6a20:d8b:b0:1e0:cc4a:caab with SMTP id adf61e73a8af0-1e1ceae20demr2907188637.19.1733986928653; Wed, 11 Dec 2024 23:02:08 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7fd552c0a6asm5350471a12.63.2024.12.11.23.02.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:02:07 -0800 (PST) From: Charlie Jenkins Date: Wed, 11 Dec 2024 23:01:43 -0800 Subject: [PATCH v6] riscv: selftests: Fix warnings pointer masking test MIME-Version: 1.0 Message-Id: <20241211-fix_warnings_pointer_masking_tests-v6-1-c7ae708fbd2f@rivosinc.com> X-B4-Tracking: v=1; b=H4sIAFaKWmcC/5XQQWrDMBAF0KsErasiyRrJ7qr3KMHY8igZSqQgG TUl+O6VswrFi3j5P8z7MHeWMRFm9nG4s4SFMsVQg3k7MHcewgk5TTUzJZSWSmju6db/DClQOOX +GinMmPrLkL9r0c+Y58yb1gjUvgGtOlaha8J69Rj5OtZ8pjzH9PvYLHJtd/FFcslxkNgZAw7t8 JmoxEzBvbt4YetCUftVVVU5euFAdOCh3VCbZxVeUpuqglPtKHxntJg2VL1f1VUVzlocrQLdmg0 VnlXzkgrrXycwximvLP7/wLIsf6r477gvAgAA X-Change-ID: 20241204-fix_warnings_pointer_masking_tests-3860e4f35429 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.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3794; i=charlie@rivosinc.com; h=from:subject:message-id; bh=oRAcg2/hExWeoK3VTcSjnjMHrzycrG0KO39nZHe9kSA=; b=owGbwMvMwCHWx5hUnlvL8Y3xtFoSQ3pUV8Y5ae794gckLbey7U68dcarPu/979j780O1XLx+8 t4SMrjbUcrCIMbBICumyMJzrYG59Y5+2VHRsgkwc1iZQIYwcHEKwESYhRgZXrxw/5qz8mrnrK4F mpvXnHG2yeJUfc03i7U4zno+21LOUob/WSePyZ79cthSSVBt+obtc+62r8i//qdzB9Oj600LZgY lMgIA 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-20241211_230210_490671_FA84D8E8 X-CRM114-Status: GOOD ( 11.91 ) 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 v6: - Add back ksft_test_result() (Samuel) - Link to v5: https://lore.kernel.org/r/20241206-fix_warnings_pointer_masking_tests-v5-1-ed566c2f27e8@rivosinc.com 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 | 28 +++++++++++++++++----- 1 file changed, 22 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 dee41b7ee3e323150d55523c8acbf3ec38857b87..059d2e87eb1f737caf44f692b239bf3e49c233b4 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,18 @@ 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); + else + ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == -EINVAL, + "sysctl disabled\n"); 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); + else + ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == 0, + "sysctl enabled\n"); set_tagged_addr_ctrl(0, false);