Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1316232imm; Wed, 17 Oct 2018 17:58:13 -0700 (PDT) X-Google-Smtp-Source: ACcGV63QVxbx2Vs1KE5P5bijtFiTNtyA9VoM3/pty5sJghxqZ6mpiQ5+ZNGsG5riYhQy91bDbHzi X-Received: by 2002:a65:4783:: with SMTP id e3-v6mr26019087pgs.12.1539824293157; Wed, 17 Oct 2018 17:58:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539824293; cv=none; d=google.com; s=arc-20160816; b=boZO+ZH+1Xn6o/GVBM4Kqf6Ly2DYMxexWYARJpfVpMn1JM5FfFgovrxjzCr/ks6jst gTCt+c/j4o9w5Tx9GnfT/uGt3lcjNsXo8bU0u//pEHR5YmLA2ulGZ7uutIgb5ZciKIA0 x9UR0AavfH8Y10vUY/9n2x8OlFAIT+LJ+pin8Yu6kS4KY6B6gAi7QBlQPLNQdcQljV+s y7nGDH8ZaElB5pYFMZMWtgeZtLRFNaHvavvw11UK3D7y/YhX4L5TjolW2RQ0aYSLFjN8 Mdl98r1JsKP9YMCueYe58eIz5ckNxwZPUJLusMZocV+DBZUNBnkdatc3C/a/p7BHY5md 1ZAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=TJW7HsI+4GhXXdQy7Scxoh1s2Wf7qgckbpAjTS5xl20=; b=H+LHrIOp5Hl276B+En31BwBjkBzkBzvs0nxaIADJEZywTnZdZ3Tq6AG8IDvTUx5szS LjyM3b4Mazjomv8YcCdvrWvsJg6z/RLVlA1IIRaznWbL36R2yXOkRW385hVQTDlqJLSj a1d2a5wnVHhppY2q5016oaisIWX1B19nVjOwJ9RK8LgXQPOWWb+JvM3CJfGVz0BmSzgt AwEvKnzV25sQIaj4CmoPi9RxA50EmdKjjxdrVvNwzFzKT9K3xMKsy8FwQ78DOUf2pT63 2TecS2yfmG4kbdfiLgnU1AHxtRuuHeRhVc5lLCnFJqXQpAQ4JxMlBaLfyogkyaRjzTsb lVpQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w24-v6si17518462pgi.313.2018.10.17.17.57.57; Wed, 17 Oct 2018 17:58:13 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727267AbeJRIya (ORCPT + 99 others); Thu, 18 Oct 2018 04:54:30 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:1559 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726943AbeJRIya (ORCPT ); Thu, 18 Oct 2018 04:54:30 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Wed, 17 Oct 2018 17:55:52 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 3FE96408AB; Wed, 17 Oct 2018 17:56:09 -0700 (PDT) From: Nadav Amit To: Ingo Molnar CC: Andy Lutomirski , Peter Zijlstra , "H . Peter Anvin " , Thomas Gleixner , , Nadav Amit , , Borislav Petkov , David Woodhouse , Nadav Amit Subject: [RFC PATCH 1/5] x86: introduce preemption disable prefix Date: Wed, 17 Oct 2018 17:54:16 -0700 Message-ID: <20181018005420.82993-2-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181018005420.82993-1-namit@vmware.com> References: <20181018005420.82993-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-002.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is sometimes beneficial to prevent preemption for very few instructions, or prevent preemption for some instructions that precede a branch (this latter case will be introduced in the next patches). To provide such functionality on x86-64, we use an empty REX-prefix (opcode 0x40) as an indication that preemption is disabled for the following instruction. It is expected that this opcode is not in common use. Signed-off-by: Nadav Amit --- arch/x86/entry/entry_64.S | 10 ++++++++++ arch/x86/include/asm/nospec-branch.h | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index cb8a5893fd33..31d59aad496e 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -643,6 +643,16 @@ retint_kernel: jnc 1f 0: cmpl $0, PER_CPU_VAR(__preempt_count) jnz 1f + + /* + * Allow to use hint to prevent preemption on a certain instruction. + * Consider an instruction with the first byte having REX prefix + * without any bits set as an indication for preemption disabled. + */ + movq RIP(%rsp), %rax + cmpb $PREEMPT_DISABLE_PREFIX, (%rax) + jz 1f + call preempt_schedule_irq jmp 0b 1: diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index 80dc14422495..0267611eb247 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -52,6 +52,12 @@ jnz 771b; \ add $(BITS_PER_LONG/8) * nr, sp; +/* + * An empty REX-prefix is an indication that preemption should not take place on + * this instruction. + */ +#define PREEMPT_DISABLE_PREFIX (0x40) + #ifdef __ASSEMBLY__ /* @@ -148,6 +154,12 @@ #endif .endm +.macro preempt_disable_prefix +#ifdef CONFIG_PREEMPT + .byte PREEMPT_DISABLE_PREFIX +#endif +.endm + #else /* __ASSEMBLY__ */ #define ANNOTATE_NOSPEC_ALTERNATIVE \ -- 2.17.1