Received: by 10.223.164.202 with SMTP id h10csp1018562wrb; Tue, 7 Nov 2017 19:55:55 -0800 (PST) X-Google-Smtp-Source: ABhQp+TMOy22pNRzJ3EsWIVOl4IcqmJwuH7qExckCthL32x2djJldoBUFzAE3D7Hq7NP+AacEpgB X-Received: by 10.84.233.70 with SMTP id k6mr940932plt.134.1510113355619; Tue, 07 Nov 2017 19:55:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510113355; cv=none; d=google.com; s=arc-20160816; b=qDMghMqzLEJqoXhn7ZAPWZ4IJAwYbd7tIRsKFRPQrS5xgxeTlGtppE+yTaXuZgZbvt 3V0l77Wu7eFjv8TIM+jenuzDO9nd25TAEAa1lZZyLE2+MQLEK5LpZucMukg9+yNDrTsd 6koD5pSM6Zkzdr3K/wJk74YjCpzAEeAyFjQ8JTmigMV9uRrzoXi0mPfKzD6jU+IhvNw3 OQfUGiWr+RmP6/lt8sUHgtzuamr6eAP5Hn6Y0DcSwfz/TqZSQAEJ/GlBZtqR0ushpWfC Ss35R+WPaxVTlhX+cJHT5wEiLIi1brYvbgDIim8XbupULATR1uxeNjKkXmXhBpKejgwc gwAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=9o8YrobFD9PT8fNbXzYagMiWXjb0KBXGID2DtO6aJ3A=; b=vV4nB+gCXi9wmwVuR76+cTnmmTwuRcUwZ8qY2Jm9w3VoD4XV6mNiPQ1yuuVf6U7GwO a9T73yKhEGpX69Xi5UxCpZXB7ZcGKCMyYMv2En/e8WJ/YfbJrCCEblbh8sM9LqcU2A9h p3IAr+uc8jGx6ULRx+bx4cYjLK/2HRoMcPycu9OT/VC2OIlYh47U9pyuO6gC65OhjZss YtjLyy73WMu4SsksGXoAqGHusTRg8O3r0meIWj11tMRc8+rHyCjPVI/QYsunCRORplXw pwxp+bjm8wZFdRj/bqspOflHMUeRAPvUO5VE3Rq/jpuKxvSt4QKXmAxCKld/2xV4nwtd E7+Q== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y12si2442552plt.757.2017.11.07.19.55.43; Tue, 07 Nov 2017 19:55:55 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753786AbdKHCZy (ORCPT + 90 others); Tue, 7 Nov 2017 21:25:54 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:36572 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752908AbdKHCY0 (ORCPT ); Tue, 7 Nov 2017 21:24:26 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vA82NrBV053162 for ; Tue, 7 Nov 2017 21:24:25 -0500 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e3mq3b2ad-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 07 Nov 2017 21:24:25 -0500 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 7 Nov 2017 19:24:24 -0700 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 7 Nov 2017 19:24:21 -0700 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vA82OLdW3342666; Tue, 7 Nov 2017 19:24:21 -0700 Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1797E6A03F; Tue, 7 Nov 2017 19:24:21 -0700 (MST) Received: from suka-w540.usor.ibm.com (unknown [9.70.94.25]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP id 994706A03D; Tue, 7 Nov 2017 19:24:20 -0700 (MST) From: Sukadev Bhattiprolu To: Michael Ellerman Cc: Benjamin Herrenschmidt , mikey@neuling.org, hbabu@us.ibm.com, nicholas.piggin@gmail.com, linuxppc-dev@ozlabs.org, Subject: [PATCH v3 14/18] powerpc: Define set_thread_uses_vas() Date: Tue, 7 Nov 2017 18:23:54 -0800 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510107838-15181-1-git-send-email-sukadev@linux.vnet.ibm.com> References: <1510107838-15181-1-git-send-email-sukadev@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17110802-0028-0000-0000-0000089DBC83 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008029; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00942691; UDB=6.00475553; IPR=6.00722980; BA=6.00005677; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017903; XFM=3.00000015; UTC=2017-11-08 02:24:23 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17110802-0029-0000-0000-0000383F098D Message-Id: <1510107838-15181-15-git-send-email-sukadev@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-07_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1711080027 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A CP_ABORT instruction is required in processes that have mapped a VAS "paste address" with the intention of using COPY/PASTE instructions. But since CP_ABORT is expensive, we want to restrict it to only processes that use/intend to use COPY/PASTE. Define an interface, set_thread_uses_vas(), that VAS can use to indicate that the current process opened a send window. During context switch, issue CP_ABORT only for processes that have the flag set. Thanks for input from Nick Piggin, Michael Ellerman. Cc: Nicholas Piggin Signed-off-by: Sukadev Bhattiprolu --- Changelog[v3]: - [Nick Piggin] Rename interface to set_thread_uses_vas(), tweak comment and move the CP_ABORT from callers into the interface. --- arch/powerpc/include/asm/processor.h | 2 ++ arch/powerpc/include/asm/switch_to.h | 2 ++ arch/powerpc/kernel/process.c | 41 +++++++++++++++++++++++++++--------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h index 58cc212..bdab3b74 100644 --- a/arch/powerpc/include/asm/processor.h +++ b/arch/powerpc/include/asm/processor.h @@ -341,7 +341,9 @@ struct thread_struct { unsigned long sier; unsigned long mmcr2; unsigned mmcr0; + unsigned used_ebb; + unsigned int used_vas; #endif }; diff --git a/arch/powerpc/include/asm/switch_to.h b/arch/powerpc/include/asm/switch_to.h index ad2d762..c3ca42c 100644 --- a/arch/powerpc/include/asm/switch_to.h +++ b/arch/powerpc/include/asm/switch_to.h @@ -92,6 +92,8 @@ static inline void clear_task_ebb(struct task_struct *t) #endif } +extern int set_thread_uses_vas(void); + extern int set_thread_tidr(struct task_struct *t); extern void clear_thread_tidr(struct task_struct *t); diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index d861fcd..395ca80 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -1234,17 +1234,17 @@ struct task_struct *__switch_to(struct task_struct *prev, * The copy-paste buffer can only store into foreign real * addresses, so unprivileged processes can not see the * data or use it in any way unless they have foreign real - * mappings. We don't have a VAS driver that allocates those - * yet, so no cpabort is required. + * mappings. If the new process has the foreign real address + * mappings, we must issue a cp_abort to clear any state and + * prevent snooping, corruption or a covert channel. + * + * DD1 allows paste into normal system memory so we do an + * unpaired copy, rather than cp_abort, to clear the buffer, + * since cp_abort is quite expensive. */ - if (cpu_has_feature(CPU_FTR_POWER9_DD1)) { - /* - * DD1 allows paste into normal system memory, so we - * do an unpaired copy here to clear the buffer and - * prevent a covert channel being set up. - * - * cpabort is not used because it is quite expensive. - */ + if (new_thread->used_vas) { + asm volatile(PPC_CP_ABORT); + } else if (cpu_has_feature(CPU_FTR_POWER9_DD1)) { asm volatile(PPC_COPY(%0, %1) : : "r"(dummy_copy_buffer), "r"(0)); } @@ -1445,6 +1445,27 @@ void flush_thread(void) #endif /* CONFIG_HAVE_HW_BREAKPOINT */ } +int set_thread_uses_vas(void) +{ +#ifdef CONFIG_PPC_BOOK3S_64 + if (!cpu_has_feature(CPU_FTR_ARCH_300)) + return -EINVAL; + + current->thread.used_vas = 1; + + /* + * Even a process that has no foreign real address mapping can use + * an unpaired COPY instruction (to no real effect). Issue CP_ABORT + * to clear any pending COPY and prevent a covert channel. + * + * __switch_to() will issue CP_ABORT on future context switches. + */ + asm volatile(PPC_CP_ABORT); + +#endif /* CONFIG_PPC_BOOK3S_64 */ + return 0; +} + #ifdef CONFIG_PPC64 static DEFINE_SPINLOCK(vas_thread_id_lock); static DEFINE_IDA(vas_thread_ida); -- 2.7.4 From 1583361873049032586@xxx Mon Nov 06 23:39:11 +0000 2017 X-GM-THRID: 1583361873049032586 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread