Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp22432ybt; Tue, 30 Jun 2020 14:00:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOxm1muIBcjqpxIg+RwHYWAaA0So1ZMHa9Mw4mZULtDIE+HYZGQbvYdebnAL9sy5fMHNSQ X-Received: by 2002:aa7:c883:: with SMTP id p3mr25882306eds.128.1593550443549; Tue, 30 Jun 2020 13:54:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593550443; cv=none; d=google.com; s=arc-20160816; b=liKxltbT5QMcgb0J+7HoGU42k2hKoaQV7lS4ngMyr2ld15PxyHbNZlxbuEp9VndccO 9jONSYC3jC83rLNZSicwz3WWAeg2n3Cv8KaScx9pJaQytvFQCXMOpUXbGbY2qaI5kQDi duDxIamXGd5hSg2HLHjbtM0/N6GnJ9xDJZqoLgdzPWs3C7uwtHCFPHdQfg8GhYr262HJ y1JZm5CMWSCw30KZuTFiFh4fzjmXIHEistykWwRltZj+pVP1EDX8S0O8onQSVf55tQXV vu2L0qazBJmP6rvg6EvZKrhicmUHJ50yxYpy5t7ykEO4tCvKZhfpQNIzsj54z5VpW14Z lm/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=H+NwmQsMcWtz3uTzldfpzS2P1c0M/yj9ueEZxoOkGFQ=; b=OsLktEU3QjN/6h+jfdCMR7HChtXyMYRnQ2km4lDmF5VK3AbkMxqh/a3Bhvj1maCeTu 2nOIyKFNJSvEYHwxTQc1QdTmRQz299vR1RFjGiubo3I/HPoIcNfmWVGIvm36Njh07QBr +my0Kio0/kDHIma5sDgzJ7o3vqxMFSzc6q/c6XbYUap+vpMaLudDCVzUyqPPTJOECOok n/xXxvmmnTxAY6iDjKoTjT9TncdE4F2m6fTlnSzxEG05d0IA/SrKBolVfpz9TuFRBVk+ NdLzyO1hM/Tf1xqmzuKe7uvOEh0d+UzYkMa8/aKEvM7Plwl7AKxcImqNNBGNvh4HLPfr wloA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v15si2416949edl.205.2020.06.30.13.53.39; Tue, 30 Jun 2020 13:54:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728643AbgF3TtL (ORCPT + 99 others); Tue, 30 Jun 2020 15:49:11 -0400 Received: from foss.arm.com ([217.140.110.172]:33012 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728545AbgF3TtA (ORCPT ); Tue, 30 Jun 2020 15:49:00 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6D8D631B; Tue, 30 Jun 2020 12:48:59 -0700 (PDT) Received: from seattle-bionic.arm.com.Home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 80BDC3F73C; Tue, 30 Jun 2020 12:48:58 -0700 (PDT) From: Oliver Swede To: Will Deacon , Catalin Marinas Cc: Robin Murphy , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 14/14] arm64: Improve accuracy of fixup for UAO cases Date: Tue, 30 Jun 2020 19:48:22 +0000 Message-Id: <20200630194822.1082-15-oli.swede@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200630194822.1082-1-oli.swede@arm.com> References: <20200630194822.1082-1-oli.swede@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This accounts for variations in the number of bytes copied to the destination buffer that could result from the substitution of STP instructions with 2x unprivileged STTR variants if UAO is supported and enabled. Rather than duplicating the store fixups with the modifications, the relevant alternatives are inserted in-line. Signed-off-by: Oliver Swede --- arch/arm64/lib/copy_user_fixup.S | 47 ++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/arch/arm64/lib/copy_user_fixup.S b/arch/arm64/lib/copy_user_fixup.S index 37ca3d99a02a..2d413f9ba5d3 100644 --- a/arch/arm64/lib/copy_user_fixup.S +++ b/arch/arm64/lib/copy_user_fixup.S @@ -205,7 +205,12 @@ addr .req x15 /* 32 < count < 128 -> count - ((addr-dst)&15) */ cmp count, 128 sub x0, addr, dst // relative fault offset + /* fault offset within dest. buffer */ + alternative_if ARM64_HAS_UAO + bic x0, x0, 7 // stp subst. for 2x sttr + alternative_else bic x0, x0, 15 // bytes already copied (steps of 16B stores) + alternative_endif sub x0, count, x0 // bytes yet to copy b.le L(end_fixup) /* 128 < count -> count */ @@ -265,7 +270,12 @@ addr .req x15 sub tmp1, count, tmp1 // remaining bytes after non-overlapping section sub x0, dstend, 64 sub x0, addr, x0 - bic x0, x0, 15 // fault offset within dest. buffer + /* fault offset within dest. buffer */ + alternative_if ARM64_HAS_UAO + bic x0, x0, 7 // stp subst. for 2x sttr + alternative_else + bic x0, x0, 15 // bytes already copied (steps of 16B stores) + alternative_endif add x0, dstend, x0 sub x0, x0, 64 sub x0, dstend, x0 // remaining bytes in final (overlapping) 64B @@ -295,7 +305,12 @@ addr .req x15 */ sub tmp1, dstend, 32 sub tmp1, addr, tmp1 - bic tmp1, tmp1, 15 + /* fault offset */ + alternative_if ARM64_HAS_UAO + bic tmp1, tmp1, 7 // stp subst. for 2x sttr + alternative_else + bic tmp1, tmp1, 15 // bytes already copied (steps of 16B stores) + alternative_endif mov x0, 32 sub tmp1, x0, tmp1 sub x0, count, 32 @@ -309,7 +324,12 @@ addr .req x15 */ sub tmp1, dstend, 32 sub tmp1, addr, tmp1 - bic tmp1, tmp1, 15 + /* fault offset */ + alternative_if ARM64_HAS_UAO + bic tmp1, tmp1, 7 // stp subst. for 2x sttr + alternative_else + bic tmp1, tmp1, 15 // bytes already copied (steps of 16B stores) + alternative_endif mov x0, 32 sub tmp1, x0, tmp1 sub x0, count, 64 @@ -324,7 +344,12 @@ addr .req x15 */ sub tmp1, dstend, 64 sub tmp1, addr, tmp1 - bic tmp1, tmp1, 15 + /* fault offset */ + alternative_if ARM64_HAS_UAO + bic tmp1, tmp1, 7 // stp subst. for 2x sttr + alternative_else + bic tmp1, tmp1, 15 // bytes already copied (steps of 16B stores) + alternative_endif mov x0, 64 sub tmp1, x0, tmp1 cmp count, 128 @@ -378,10 +403,20 @@ addr .req x15 /* Take the min from {16,(fault_addr&15)-(dst&15)} * and subtract from count to obtain the return value */ bic tmp1, dst, 15 // aligned dst - bic x0, addr, 15 + /* fault offset */ + alternative_if ARM64_HAS_UAO + bic x0, addr, 7 // stp subst. for 2x sttr + alternative_else + bic x0, addr, 15 // bytes already copied (steps of 16B stores) + alternative_endif sub x0, x0, tmp1 // relative fault offset cmp x0, 16 - bic x0, addr, 15 + /* fault offset */ + alternative_if ARM64_HAS_UAO + bic x0, addr, 7 // stp subst. for 2x sttr + alternative_else + bic x0, addr, 15 // bytes already copied (steps of 16B stores) + alternative_endif sub x0, x0, dst sub x0, count, x0 b.gt L(end_fixup) -- 2.17.1