Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp59213ybi; Thu, 11 Jul 2019 14:40:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqw5FifjYFNyIV8oIbsaJmJjHamcKbXt/j+w11LGrud/RwkNmcGh/n78Msno9buQ8RgUZ2ci X-Received: by 2002:a17:90a:1ae1:: with SMTP id p88mr6999726pjp.26.1562881202089; Thu, 11 Jul 2019 14:40:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562881202; cv=none; d=google.com; s=arc-20160816; b=fys08BKeAR4+DC3Kgb1RC8wB8Egb0/fVD+L2U/S4zWzzbOEhQbLCUUOmFXNT3b5T+a eF7wXJlIyc0doNTF6NkrYISNfAKc+ER3ubSl8pfUHcwo2ZNMkEJIQMY1M45APEa9oMTW IX7x4mK38xvQWH55ZwA/MZ0GLak+D0fFYvENPve6yxVGXRXEfDOa4dv5G0rnuylJVZM3 eVeqj815H345yEc+wvjnMPNDRkFdVVR+uVlcudfiAYW0+qG4BfWSR9ajbDd3snnyo7Dq WVOIFwiU8GMfaGNh118RzcJBXuaLXqEBO0def2zrrSVA9JsmZFnJpmVtR59LOJHk2aP5 5BhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=4DbAui3JRthBbn+rH3ZbT6KQozOdSL1BfgrMWL8KxQU=; b=QsZmV+pGzPlfmT7Kz68Y+xLHQ10Xw2CL+rcHfqnHg7XQmIF3aExDTEtWms3I9Jh374 b+wbYhGgRyNWAZpEpUAAyzq5gsd7csmhcCth3WfgrK99qaCpFqhou8ePrFOJJwQ21N0h IbFphEPT3kOa4s2ipVoD8I/MBH1RjBbHv3C8HOz4z6q0Jw3VyyqoJpM7D2jGMTqd3YsI 44vfpbKpSmwm3rzwljm4+8/DKn0/H1yVZug3H23lo+h4SaZIvsGSAvxHbu4WAS4ybsIC JbKXMtKrwZf6BPsXbe4/LnJglszh4jUVFLSih8wCRuqD8C4DLeAVwIJ44Nssff+oMDcp CiJg== 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 r145si6314683pgr.553.2019.07.11.14.39.46; Thu, 11 Jul 2019 14:40:02 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728601AbfGKVeS (ORCPT + 99 others); Thu, 11 Jul 2019 17:34:18 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:42312 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726199AbfGKVeS (ORCPT ); Thu, 11 Jul 2019 17:34:18 -0400 Received: from pd9ef1cb8.dip0.t-ipconnect.de ([217.239.28.184] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1hlghS-000289-8D; Thu, 11 Jul 2019 23:33:58 +0200 Date: Thu, 11 Jul 2019 23:33:50 +0200 (CEST) From: Thomas Gleixner To: Alexandre Chartre cc: pbonzini@redhat.com, rkrcmar@redhat.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, kvm@vger.kernel.org, x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, konrad.wilk@oracle.com, jan.setjeeilers@oracle.com, liran.alon@oracle.com, jwadams@google.com, graf@amazon.de, rppt@linux.vnet.ibm.com Subject: Re: [RFC v2 01/26] mm/x86: Introduce kernel address space isolation In-Reply-To: <1562855138-19507-2-git-send-email-alexandre.chartre@oracle.com> Message-ID: References: <1562855138-19507-1-git-send-email-alexandre.chartre@oracle.com> <1562855138-19507-2-git-send-email-alexandre.chartre@oracle.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 11 Jul 2019, Alexandre Chartre wrote: > +/* > + * When isolation is active, the address space doesn't necessarily map > + * the percpu offset value (this_cpu_off) which is used to get pointers > + * to percpu variables. So functions which can be invoked while isolation > + * is active shouldn't be getting pointers to percpu variables (i.e. with > + * get_cpu_var() or this_cpu_ptr()). Instead percpu variable should be > + * directly read or written to (i.e. with this_cpu_read() or > + * this_cpu_write()). > + */ > + > +int asi_enter(struct asi *asi) > +{ > + enum asi_session_state state; > + struct asi *current_asi; > + struct asi_session *asi_session; > + > + state = this_cpu_read(cpu_asi_session.state); > + /* > + * We can re-enter isolation, but only with the same ASI (we don't > + * support nesting isolation). Also, if isolation is still active, > + * then we should be re-entering with the same task. > + */ > + if (state == ASI_SESSION_STATE_ACTIVE) { > + current_asi = this_cpu_read(cpu_asi_session.asi); > + if (current_asi != asi) { > + WARN_ON(1); > + return -EBUSY; > + } > + WARN_ON(this_cpu_read(cpu_asi_session.task) != current); > + return 0; > + } > + > + /* isolation is not active so we can safely access the percpu pointer */ > + asi_session = &get_cpu_var(cpu_asi_session); get_cpu_var()?? Where is the matching put_cpu_var() ? get_cpu_var() contains a preempt_disable ... What's wrong with a simple this_cpu_ptr() here? > +void asi_exit(struct asi *asi) > +{ > + struct asi_session *asi_session; > + enum asi_session_state asi_state; > + unsigned long original_cr3; > + > + asi_state = this_cpu_read(cpu_asi_session.state); > + if (asi_state == ASI_SESSION_STATE_INACTIVE) > + return; > + > + /* TODO: Kick sibling hyperthread before switching to kernel cr3 */ > + original_cr3 = this_cpu_read(cpu_asi_session.original_cr3); > + if (original_cr3) Why would this be 0 if the session is active? > + write_cr3(original_cr3); > + > + /* page-table was switched, we can now access the percpu pointer */ > + asi_session = &get_cpu_var(cpu_asi_session); See above. > + WARN_ON(asi_session->task != current); > + asi_session->state = ASI_SESSION_STATE_INACTIVE; > + asi_session->asi = NULL; > + asi_session->task = NULL; > + asi_session->original_cr3 = 0; > +} Thanks, tglx