From patchwork Tue Oct 13 04:37:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Neuling X-Patchwork-Id: 1381321 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C9P1s4pM8z9sS8 for ; Tue, 13 Oct 2020 16:17:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=neuling.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=neuling.org header.i=@neuling.org header.a=rsa-sha256 header.s=201811 header.b=BEhshRqj; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4C9P1s3QFzzDqhH for ; Tue, 13 Oct 2020 16:17:37 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4C9NwS6N5fzDqg4 for ; Tue, 13 Oct 2020 16:12:56 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=neuling.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=neuling.org header.i=@neuling.org header.a=rsa-sha256 header.s=201811 header.b=BEhshRqj; dkim-atps=neutral Received: from neuling.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 4C9NwR6BqZz9sS8; Tue, 13 Oct 2020 16:12:55 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=neuling.org; s=201811; t=1602565976; bh=Upm3YHeWjavWhY2f/aGvlXp+ccdKU/8n71IQMcqWZzw=; h=From:To:Cc:Subject:Date:From; b=BEhshRqjqe4ENXx0xkSW0OkGaA8Rox6pao9eTao+ojG5YGfgD3tfcczl3vUSQoEYR UfQJvccbbPK3X4rJVkd4TYxHTB8XmxmtJFEKh4mIdhTriB6AatIrsgw+1F+jJK9tmH JBQ3Ws/wR6gLqpV/WxNovg5984tsTrlt/Emxw+lJVcNjk37yqr+ZX6ka1QXyTgRvay 32evNkWQtNUsLhc7yGCPHYUuV1b5GQGbuZQ99rwxugWaTYuNFk3U86G6kxN4I0Rh0w H/cfxRzjDG78RgseSkFGSlmPBkPT9+nyAGLMqD5Lo91jWcJ/dD39AzklxU2B63Lk8k fDFuBPVUZ0QDg== Received: by neuling.org (Postfix, from userid 1000) id 2A5EB2C06AD; Tue, 13 Oct 2020 15:37:43 +1100 (AEDT) From: Michael Neuling To: mpe@ellerman.id.au Subject: [PATCH 1/2] powerpc: Fix user data corruption with P9N DD2.1 VSX CI load workaround emulation Date: Tue, 13 Oct 2020 15:37:40 +1100 Message-Id: <20201013043741.743413-1-mikey@neuling.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mikey@neuling.org, linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" __get_user_atomic_128_aligned() stores to kaddr using stvx which is a VMX store instruction, hence kaddr must be 16 byte aligned otherwise the store won't occur as expected. Unfortunately when we call __get_user_atomic_128_aligned() in p9_hmi_special_emu(), the buffer we pass as kaddr (ie. vbuf) isn't guaranteed to be 16B aligned. This means that the write to vbuf in __get_user_atomic_128_aligned() has the bottom bits of the address truncated. This results in other local variables being overwritten. Also vbuf will not contain the correct data which results in the userspace emulation being wrong and hence user data corruption. In the past we've been mostly lucky as vbuf has ended up aligned but this is fragile and isn't always true. CONFIG_STACKPROTECTOR in particular can change the stack arrangement enough that our luck runs out. This issue only occurs on POWER9 Nimbus <= DD2.1 bare metal. The fix is to align vbuf to a 16 byte boundary. Fixes: 5080332c2c89 ("powerpc/64s: Add workaround for P9 vector CI load issue") Signed-off-by: Michael Neuling Cc: # v4.15+ --- arch/powerpc/kernel/traps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c index c5f39f13e96e..5006dcbe1d9f 100644 --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -885,7 +885,7 @@ static void p9_hmi_special_emu(struct pt_regs *regs) { unsigned int ra, rb, t, i, sel, instr, rc; const void __user *addr; - u8 vbuf[16], *vdst; + u8 vbuf[16] __aligned(16), *vdst; unsigned long ea, msr, msr_mask; bool swap; From patchwork Tue Oct 13 04:37:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Neuling X-Patchwork-Id: 1381314 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C9NyT4Zfgz9sVY for ; Tue, 13 Oct 2020 16:14:41 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=neuling.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=neuling.org header.i=@neuling.org header.a=rsa-sha256 header.s=201811 header.b=AftGI4GL; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4C9NyS6ZdzzDqgP for ; Tue, 13 Oct 2020 16:14:40 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4C9NwT0Y6XzDqg7 for ; Tue, 13 Oct 2020 16:12:57 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=neuling.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=neuling.org header.i=@neuling.org header.a=rsa-sha256 header.s=201811 header.b=AftGI4GL; dkim-atps=neutral Received: from neuling.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 4C9NwR6BrTz9sTr; Tue, 13 Oct 2020 16:12:55 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=neuling.org; s=201811; t=1602565976; bh=Ffqd4hXCoAPgLS4eS0R3VPQY6UYl3q0HkeF9N/L79fA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AftGI4GL1rpdjAz9z/FmlE/fIEAXlkC/Sb+yOzVatsFcalQwePLE0JAx1X4bOPA5t gng55pmi90oRIf7dJFH9Tb4Xbzzuo1xI/zItpmhvsDy3iBFIC4S1Yp3i/brbbWZRqa cTcL4OtOwI470raarNu+UyvWY+GbgL3zpIqJ/ubSqZRzDagePWWs2S6t4KbxoXwWMQ aCjSfTab4we8lBKCcJ+qnNbiXgFZZvFGak25YzxpZtjbGiHh6U41/Jrl7qlHMFURzo Wqm9e+gWCZdAYggtNyE5tpr8TSf4jMuVPuz6FNhDEb3nTT+ghJ+G4tLlZYtZ63HYFQ HmNCOF//D0t2Q== Received: by neuling.org (Postfix, from userid 1000) id 2EFEA2C031D; Tue, 13 Oct 2020 15:37:43 +1100 (AEDT) From: Michael Neuling To: mpe@ellerman.id.au Subject: [PATCH 2/2] selftests/powerpc: Make alignment handler test P9N DD2.1 vector CI load workaround Date: Tue, 13 Oct 2020 15:37:41 +1100 Message-Id: <20201013043741.743413-2-mikey@neuling.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201013043741.743413-1-mikey@neuling.org> References: <20201013043741.743413-1-mikey@neuling.org> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mikey@neuling.org, linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" alignment_handler currently only tests the unaligned cases but it can also be useful for testing the workaround for the P9N DD2.1 vector CI load issue fixed by p9_hmi_special_emu(). This workaround was introduced in 5080332c2c89 ("powerpc/64s: Add workaround for P9 vector CI load issue"). This changes the loop to start from offset 0 rather than 1 so that we test the kernel emulation in p9_hmi_special_emu(). Signed-off-by: Michael Neuling --- .../selftests/powerpc/alignment/alignment_handler.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/powerpc/alignment/alignment_handler.c b/tools/testing/selftests/powerpc/alignment/alignment_handler.c index 2a0503bc7e49..cb53a8b777e6 100644 --- a/tools/testing/selftests/powerpc/alignment/alignment_handler.c +++ b/tools/testing/selftests/powerpc/alignment/alignment_handler.c @@ -266,8 +266,12 @@ int do_test(char *test_name, void (*test_func)(char *, char *)) } rc = 0; - /* offset = 0 no alignment fault, so skip */ - for (offset = 1; offset < 16; offset++) { + /* + * offset = 0 is aligned but tests the workaround for the P9N + * DD2.1 vector CI load issue (see 5080332c2c89 "powerpc/64s: + * Add workaround for P9 vector CI load issue") + */ + for (offset = 0; offset < 16; offset++) { width = 16; /* vsx == 16 bytes */ r = 0;