Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp548271ybl; Wed, 29 Jan 2020 05:28:11 -0800 (PST) X-Google-Smtp-Source: APXvYqzliXPn2TeuYNXXz1vnt8txGlYJJXWBdWuAXONhHwLXuhGouP++wyx4OPZpcmt5e5ee0buN X-Received: by 2002:a05:6808:a9c:: with SMTP id q28mr6412352oij.176.1580304491007; Wed, 29 Jan 2020 05:28:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580304491; cv=none; d=google.com; s=arc-20160816; b=VmuwMifjBczYGpGcVRfUbWYZKXc8JkMac2QIUzYZ7nPSXErdGPtf2IIPfmPiJbaee3 3ISp3mUncm26DIlu/hhepijToK1Fvam9Qft5lrlrtXYAQMS8HkxdW5wf0I2YzS0JUZ0f jvtpvDTIjBO77PxmM+x1tr2Oltg2vaGpYSbfmPIrsK2n9tgATn0gSM0vsG6s3LOUKxFy UxdgQ6di/xzeskw4aWuFDXSqE+Rt2yy4L4HiCe6/AqBlN5uMQbOa6+SySyH0QQH6GNpH dxtPxxgfV/kZqX/sBVXrQSI7QcrwAdhu7PE2PMvt69XXCjuhaU0AUdSSNkbl4hnRvZya SOiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=LhHcKMEwIHPeLLhGRdiveADor0MnWNB22obDDkdRVn4=; b=WxCReYx6OtdUiRhI7drmBJIYfnvJlkak5JvJzHts4eM/6jmEqJwhRxILCnRw59LD4s YdCNVeTDZZFTF/jATJ81Jv77NRc3UTcb3A4/qHZBQE/ktwh3k8JwNVkwaWHWFs15ds8C XaoiVV8vvqL3eRD/AFXSY2RK5cZYjZcUMa7UFxNoyQsj95n3hHQ2+eEd4OTPtF8paFrU U1Ix6pxUfEJK9Zl1qbKM8ZzdnfH9PAf/1w9SE3+Ics0XLPwWx0T4EJe77iQm3Z9RnQwd W+4XoO5PFUUodRLMltJSZWpk8wnYVON9taV4jzbLnZkqtneQxXTvZSnU3M19MM/WOZ+F ZpOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r10si1125818otk.83.2020.01.29.05.27.59; Wed, 29 Jan 2020 05:28:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726528AbgA2N0b (ORCPT + 99 others); Wed, 29 Jan 2020 08:26:31 -0500 Received: from mx2.suse.de ([195.135.220.15]:53592 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbgA2N0a (ORCPT ); Wed, 29 Jan 2020 08:26:30 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E459DAC46; Wed, 29 Jan 2020 13:26:28 +0000 (UTC) Date: Wed, 29 Jan 2020 14:26:18 +0100 From: Borislav Petkov To: Linus Torvalds Cc: Ingo Molnar , Tony Luck , Linux Kernel Mailing List , Thomas Gleixner , Borislav Petkov , Peter Zijlstra , Andrew Morton Subject: Re: [GIT PULL] x86/asm changes for v5.6 Message-ID: <20200129132618.GA30979@zn.tnic> References: <20200128165906.GA67781@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 28, 2020 at 12:06:53PM -0800, Linus Torvalds wrote: > On Tue, Jan 28, 2020 at 11:51 AM Linus Torvalds > wrote: > > > > ALTERNATIVE_2 \ > > "cmp $680, %rdx ; jb 3f ; cmpb %dil, %sil; je 4f", \ > > "movq %rdx, %rcx ; rep movsb; retq", X86_FEATURE_FSRM, \ > > "cmp $0x20, %rdx; jb 1f; movq %rdx, %rcx; rep movsb; retq", X86_FEATURE_ERMS > > Note the UNTESTED part. > > In particular, I didn't check what the priority for the alternatives > is. Since FSRM being set always implies ERMS being set too, it may be > that the ERMS case is always picked with the above code. > > So maybe the FSRM and ERMS lines need to be switched around, and > somebody should add a comment to the ALTERNATIVE_2 macro about the > priority rules for feature1 vs feature2 when both are set.. > > IOW, testing most definitely required for that patch suggestion of mine.. So what is there now before your patch is this (I've forced both X86_FEATURE_FSRM and X86_FEATURE_ERMS on a BDW guest). [ 4.238160] apply_alternatives: feat: 18*32+4, old: (__memmove+0x17/0x1a0 (ffffffff817d90d7) len: 10), repl: (ffffffff8251dbbb, len: 0), pad: 0 [ 4.239503] ffffffff817d90d7: old_insn: 48 83 fa 20 0f 82 f5 00 00 00 That's what in vmlinux: ffffffff817d90d7: 48 83 fa 20 cmp $0x20,%rdx ffffffff817d90db: 0f 82 f5 00 00 00 jb ffffffff817d91d6 which is 10 bytes. It gets replaced to: [ 4.240194] ffffffff817d90d7: final_insn: 0f 1f 84 00 00 00 00 00 66 90 ffffffff817d90d7: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1) ffffffff817d90de: 00 ffffffff817d90df: 66 90 xchg %ax,%ax I.e., NOPed out. ERMS replaces the bytes *after* these 10 bytes, note the VA: 0xffffffff817d90d7 + 0xa = 0xffffffff817d90e1 [ 4.240917] apply_alternatives: feat: 9*32+9, old: (__memmove+0x21/0x1a0 (ffffffff817d90e1) len: 6), repl: (ffffffff8251dbbb, len: 6), pad: 6 [ 4.242209] ffffffff817d90e1: old_insn: 90 90 90 90 90 90 [ 4.242823] ffffffff8251dbbb: rpl_insn: 48 89 d1 f3 a4 c3 [ 4.243503] ffffffff817d90e1: final_insn: 48 89 d1 f3 a4 c3 which turns into ffffffff817d90e1: 48 89 d1 mov %rdx,%rcx ffffffff817d90e4: f3 a4 rep movsb %ds:(%rsi),%es:(%rdi) ffffffff817d90e6: c3 retq as expected. And yes, your idea makes sense to use ALTERNATIVE_2 but as it is, it triple-faults my guest. I'll debug it more later to find out why, when I get a chance. -- Regards/Gruss, Boris. SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg