Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1479068rwb; Tue, 27 Sep 2022 13:49:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4E7FXzO88xohhxRwoef/gNNB6B5ZQx38gnc9QoLj81d/bZNZOZFroizrkaJiLeJ3yBPPEn X-Received: by 2002:a17:906:dacd:b0:780:a90c:e144 with SMTP id xi13-20020a170906dacd00b00780a90ce144mr24474799ejb.153.1664311769156; Tue, 27 Sep 2022 13:49:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664311769; cv=none; d=google.com; s=arc-20160816; b=GHgw1g+41D3MjXU5+H4ezVtr47owz6LwauxNNlmV6T2/ckGPb2QISLD+DLJ8MsMr5j 8BfnJCnrY7XB8xsQNfNotPSeaw47pLN8k1Up6BPtujgJwf/+w+wMY9q+IUEX8Ltg5cUQ 2QSZpFp9wJbvK2mmgnAnrdRfInFCnbNUeKgzyM8dP6GssNw+0YmynX/IckcHzyhUX26R DQjhOCGnXnIPLy9MwFkEtnY+04c6lU5X4l81hQ/s2yrUhXWW84Z5SLv8a67a//4Jcem/ IXYFiNWF9ZFEgQbnbDUfc+Ew52K1TJhtv6gqoDkLVC2Nez9JCp+q1bspduWzhEe4PFxh FdCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=SNLo4c9BXtM0z8UOQgf5tFMG8y138Obd6dyre72qoDc=; b=t8knxGejL4V9ihQAtCTda/FWQmvx94s98vz9z5PUBI3cYEVXuRnaPAIk8j+wJQuDVK RRq7/8HyPACVJ6Zy47AD0jLcrlZrVjN4v9I4yVRjvlIk+gjtcPhtQlmIS0OuXON/BTCH Mkp41VI3RWCrgbbKq51T5kWn2KrfJ2JgsvSKxNKLY4TsTVQSRNaMbFybwkA7AqQwnwh/ E7YV75olNyHR5kSBln0smis1EkkE3Un9tjN3DPrtqacReE/2rOBsbD2aOw2d4syTNqpI aXlFMcSqzmi82WtjP3sdpKZYUbBlvPoL4Wh4OJOTjhap3c0zmBs/45bkRtdPOWDQWKPg sPlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=YGNnK0RD; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s21-20020a1709062ed500b007817a869a3bsi2070545eji.179.2022.09.27.13.49.03; Tue, 27 Sep 2022 13:49:29 -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=@google.com header.s=20210112 header.b=YGNnK0RD; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232749AbiI0UDN (ORCPT + 99 others); Tue, 27 Sep 2022 16:03:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232734AbiI0UCZ (ORCPT ); Tue, 27 Sep 2022 16:02:25 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 558FA1C5CBF for ; Tue, 27 Sep 2022 13:01:48 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id a80so10629150pfa.4 for ; Tue, 27 Sep 2022 13:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=SNLo4c9BXtM0z8UOQgf5tFMG8y138Obd6dyre72qoDc=; b=YGNnK0RD7gMznPaSdiz+8/9d+mAhbgcMjrKjGfS4Ua0g7pNb438g/v79EXPXkPfnuH a5DqrcBgZSyqMknfCCnZfSt2baOkOFcOiroT+L7+Mns7eHGbtweRaw5F1DOX7AN7wicX Llm+dO8eq5ifmRMGFFRawrgjjoHFYDxkKzBKoKZZLmxGEmWFUV1/a8n+k5wS8imXAVaC QKINXr+UsuuOyH/ho3RNnrdCHxmI6WQ55Ed+OZmL5HR6b/jHFxAjSrzKSRocPL7eQ1j7 xZ2jVnhxMjMrRnbdIDcBPxHFcgCbvdKyHpNkMiCFxOe57ZZhYrE40AIhvoC15AQYbOOy MxIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=SNLo4c9BXtM0z8UOQgf5tFMG8y138Obd6dyre72qoDc=; b=P3a7jJyO+S6g3pwT4StZ6sfRanJIUGUov2Eg7owG497f2KSrFZXspjXbL7UpFIIVon YIgz9UhOC1gJeGvdbn/zG0B+7KXmcFX6HRXgF3/RiJweZQ5mLQ646n0EBTnQxIYYfCsn wGgG/Q06ZdpfZ5Lb5RdBtX/Ez5mQJ2TMaVzfXOouCR5F+FEgZU4xMvJv1mDTs9T3Sz0I eVh0O9mD3k3+1Xa74rUckSVPeXKrsCvFwBPJr+iRttg1Ks51NMTpAIWGZAqBRdvXBwiz bHA46rRR6gxJ9rE2e5MSnucxQY1YTTZh5Rs0fg12wKo+KuSp9l0juQSyKtKcccpEzJXJ Td3Q== X-Gm-Message-State: ACrzQf2JVv61bzo8TXcNNVxZ4aPykenGX/1MPUBJAEkzwcOIBROAqbBi Ah+bjUdLRIGtVTIVlsbcIgVFzQtRakyvTNnT9PuKoA== X-Received: by 2002:a62:1ad5:0:b0:540:4830:7df6 with SMTP id a204-20020a621ad5000000b0054048307df6mr30046652pfa.37.1664308907250; Tue, 27 Sep 2022 13:01:47 -0700 (PDT) MIME-Version: 1.0 References: <20220927172839.3708280-1-ndesaulniers@google.com> <202209271143.7B7D15D@keescook> In-Reply-To: <202209271143.7B7D15D@keescook> From: Nick Desaulniers Date: Tue, 27 Sep 2022 13:01:35 -0700 Message-ID: Subject: Re: [PATCH v2] x86, mem: move memmove to out of line assembler To: Kees Cook 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 12:24 PM Kees Cook wrote: > > 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 That was stupid of me, I updated the scratch register operand in the instruction 2 before the one at issue and forgot to update the operand for the register in question, breaking the swap. I'll use .set directives to give these more descriptive names to avoid such a mistake. .set tmp0w %di then use tmp0w everywhere. I will give names to the remaining register operands, too. Off thread, can you show me how to run the kunit tests, please? Will send a v3 shortly. > > -Kees > > -- > Kees Cook -- Thanks, ~Nick Desaulniers