Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1417024rwb; Tue, 27 Sep 2022 12:46:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5SOXwWalaLYSCGK5iOhQXFKs949yyT6Xx0QpEqG+zpaF4Jj4FFGU6nydFcsiaVdK6YE11B X-Received: by 2002:a65:6e97:0:b0:439:e6a3:9f6d with SMTP id bm23-20020a656e97000000b00439e6a39f6dmr25525287pgb.369.1664307980498; Tue, 27 Sep 2022 12:46:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664307980; cv=none; d=google.com; s=arc-20160816; b=rCc9PS+FfPcV1svZ5/ncW0xaWqB2KMgLAyYAy0H1HSWJnhl618sSsZ/Ko4hHdtjVG8 pZg+xvaKmwZBMtzN+f9r6BYSmnxMD73C5EBPgjiy1qTpGyXvI+k8ijYAJtixU9QfFP4J V8GnZSSUB1V7aEje+U/cb83aXEsq4A2X/z8PUXdSdYmbG70ioEQHgdLzTirMdKB+c5Q9 +tK8sVKS+J9qhy7VrDnrTcs+G/BgskXCE8dDnU3iy9INtCW21rQGWtsikjQmCYizVKCs Hvrc0ZdNvUs2EzDdkUBaOukubUnb453EjSGAkQwuqZTyFHG3KxSb6tRTWerBvDQ0wWIb TCKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Bys+g6AU0hW4pKg0x/ecVxR/rYZ0Qg+jTvtx/DxcQwE=; b=KG6ZqZXZhqit+cpmiSNxVH9/1QjBAgLQtgQsb+uByIXeNe1t4dAAHHvFSU2aOjcxge IQd216NlCXmdqqiOoYaeNGyUQjqDIUXPhZt+75wprgv3lu0286UbDWSsqcLozT3gXBxE Jabjn68hNF3ubB/DreLzFma7HWKqnlbIhAtv8EAWB8GoTck5fhIhsZ8oMO+WePcwguEv nGrbcXIXHx12zFcA+lnlcbPP7HqNzZmt0JLvS0ABNeKQ2b9176tXzAm0PDFEKGvUoUWx r4Jg21QKK3TWKu3xVyXlB1D/RK51nGyALyf7PaoPvk0hovYhiFAzD0zkoHLjiBK3cNNT +Okg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KnoGxcgK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020a170902b18100b0017890fb8cdcsi2631300plr.140.2022.09.27.12.46.09; Tue, 27 Sep 2022 12:46:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KnoGxcgK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231298AbiI0TYD (ORCPT + 99 others); Tue, 27 Sep 2022 15:24:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230305AbiI0TYA (ORCPT ); Tue, 27 Sep 2022 15:24:00 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABF5BD8E23 for ; Tue, 27 Sep 2022 12:23:59 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id q35-20020a17090a752600b002038d8a68fbso16498585pjk.0 for ; Tue, 27 Sep 2022 12:23:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=Bys+g6AU0hW4pKg0x/ecVxR/rYZ0Qg+jTvtx/DxcQwE=; b=KnoGxcgKb0VeWxeXkDIYTarKak1vYNSDO7qW5/R04eljpGIg/0e8HjBIbg7FNDIKx2 FRZthD0ou89mxOMItkYaYta0w9DjGI6LsKaVx7i7pHQ1DkDO/LnuyzffLYiZg56S9CiE msmmC8h3oOhfbjnulnroI1vY6CniOtCxwpcJQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=Bys+g6AU0hW4pKg0x/ecVxR/rYZ0Qg+jTvtx/DxcQwE=; b=rc9484Pcofl7zIrusGyBG2/70zCX1/38Vx8BfOCjImI+ucD+XsBN47ebuugTLct7tQ gN+RoHtIMqlYeJ7O7BJmdkqlAxrzw7NHKinvsJiq6thFjFrZ2d5VaiqpWYvFmhEPubAW 9EQGyyOZhhWhPffXQDRwQQwqHPBTwOhG2qduhtVE0iDj9HTmWiAV0AUeHm9c3CQ2vSxy DAH0JxH0Q6LawQZcqLKHU7wN/4w2We5KduAw+foCeAHfvw2iabJP0nNXS88WC6FyWf0K Ar6jazchpsFXNyQZa+Wqga9OvSLSmxvMTqKMPHFiU9vYWF8gOZq+4Ri3zn6zngOjkR6w utUw== X-Gm-Message-State: ACrzQf1CUED54chvi9NHzWzR/S5+4XcJqhj1azW6pDuZ//hXhysFWVNk fAyYGU6v+7WM0lrJ8VRVXl1Agg== X-Received: by 2002:a17:90a:fe90:b0:202:a345:b7a6 with SMTP id co16-20020a17090afe9000b00202a345b7a6mr6103501pjb.14.1664306639240; Tue, 27 Sep 2022 12:23:59 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q7-20020a17090311c700b001754fa42065sm2009217plh.143.2022.09.27.12.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 12:23:58 -0700 (PDT) Date: Tue, 27 Sep 2022 12:23:57 -0700 From: Kees Cook To: Nick Desaulniers Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Peter Zijlstra , linux-kernel@vger.kernel.org, Linus Torvalds , llvm@lists.linux.dev, Andy Lutomirski Subject: Re: [PATCH v2] x86, mem: move memmove to out of line assembler Message-ID: <202209271143.7B7D15D@keescook> References: <20220927172839.3708280-1-ndesaulniers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220927172839.3708280-1-ndesaulniers@google.com> X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 27, 2022 at 10:28:39AM -0700, Nick Desaulniers wrote: > In addition to having complex constraints that can't always be resolved, > the clobber list seems to be missing %bx and %dx, and possibly %cl. By > using numbered operands rather than symbolic operands, the constraints > are quite obnoxious to refactor. > [...] > - /* > - * Move data from 2 bytes to 3 bytes. > - */ > - ".p2align 4\n\t" > - "9:\n\t" > - "cmp $2, %0\n\t" > - "jb 10f\n\t" > - "movw 0*2(%1), %%dx\n\t" > - "movw -1*2(%1, %0), %%bx\n\t" > - "movw %%dx, 0*2(%2)\n\t" > - "movw %%bx, -1*2(%2, %0)\n\t" > - "jmp 11f\n\t" > [...] > +.set tmp0, %edi > [...] > + /* > + * Move data from 2 bytes to 3 bytes. > + */ > +.p2align 4 > +.L4_byteswap: > + cmpl $2, n > + jb .Lbyteswap > + movw 0*2(src), %di > + movw -1*2(src, n), %bx > + movw %dx, 0*2(dest) > + movw %bx, -1*2(dest, n) > + jmp .Ldone Found it (need to use %di instead of %dx). With this changed, the kunit test passes again: diff --git a/arch/x86/lib/memmove_32.S b/arch/x86/lib/memmove_32.S index 73314a391a72..9e33c9a1c595 100644 --- a/arch/x86/lib/memmove_32.S +++ b/arch/x86/lib/memmove_32.S @@ -179,7 +179,7 @@ SYM_FUNC_START(memmove) jb .Lbyteswap movw 0*2(src), %di movw -1*2(src, n), %bx - movw %dx, 0*2(dest) + movw %di, 0*2(dest) movw %bx, -1*2(dest, n) jmp .Ldone -Kees -- Kees Cook