From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 631C9C43334 for ; Mon, 13 Jun 2022 18:27:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245481AbiFMS1t (ORCPT ); Mon, 13 Jun 2022 14:27:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245179AbiFMS1g (ORCPT ); Mon, 13 Jun 2022 14:27:36 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8B051FBF5D for ; Mon, 13 Jun 2022 07:42:59 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 7F48F1F37C; Mon, 13 Jun 2022 14:42:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1655131378; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0UHKdjPy6Bns5JU9HOJ8DtOlOS3bAJA+b5m8rgKgBio=; b=VlIj+b5wp6wNoC8k9sphH8CkQ8KHHJSXYaUqGAzVkngoAqegTWfJcffEGDokC6INtsEddy g7c+noQRC5WXz1xD5pkZ1IAIoh7KDqK6zk5dz52DVVnWQR3h7fbgrvoQCouktpkVupf6K/ iMzWP6doIajR/FOTbIl5cb9dQcsmADA= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id CE8B22C141; Mon, 13 Jun 2022 14:42:57 +0000 (UTC) Date: Mon, 13 Jun 2022 16:42:57 +0200 From: Michal Hocko To: "Kirill A. Shutemov" Cc: Dave Hansen , Andy Lutomirski , Peter Zijlstra , x86@kernel.org, Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv3 6/8] x86/mm: Provide ARCH_GET_UNTAG_MASK and ARCH_ENABLE_TAGGED_ADDR Message-ID: References: <20220610143527.22974-1-kirill.shutemov@linux.intel.com> <20220610143527.22974-7-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220610143527.22974-7-kirill.shutemov@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 10-06-22 17:35:25, Kirill A. Shutemov wrote: [...] > diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c > index 1962008fe743..93c8eba1a66d 100644 > --- a/arch/x86/kernel/process_64.c > +++ b/arch/x86/kernel/process_64.c > @@ -742,6 +742,32 @@ static long prctl_map_vdso(const struct vdso_image *image, unsigned long addr) > } > #endif > > +static int prctl_enable_tagged_addr(unsigned long nr_bits) > +{ > + struct mm_struct *mm = current->mm; > + > + /* Already enabled? */ > + if (mm->context.lam_cr3_mask) > + return -EBUSY; > + > + /* LAM has to be enabled before spawning threads */ > + if (get_nr_threads(current) > 1) > + return -EBUSY; This will not be sufficient in general. You can have mm shared with a process without CLONE_THREAD. So you would also need to check also MMF_MULTIPROCESS. But I do remember that general get_nr_threads is quite tricky to use properly. Make sure to CC Oleg Nesterov for more details. Also how does this work when the mm is shared with a kernel thread? > + > + if (!nr_bits) { > + return -EINVAL; > + } else if (nr_bits <= 6) { > + mm->context.lam_cr3_mask = X86_CR3_LAM_U57; > + mm->context.untag_mask = ~GENMASK(62, 57); > + } else { > + return -EINVAL; > + } > + > + /* Update CR3 to get LAM active */ > + switch_mm(current->mm, current->mm, current); > + return 0; > +} -- Michal Hocko SUSE Labs