Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp6664740ybp; Tue, 15 Oct 2019 19:25:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqzIZdiq+49nN3C6aO2UFqCPQFESzZWsvvkkH6fMnpaRWNWvq8i53OI0kr97bL0/9K/VOnC7 X-Received: by 2002:a17:906:cc85:: with SMTP id oq5mr36556697ejb.81.1571192738053; Tue, 15 Oct 2019 19:25:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571192738; cv=none; d=google.com; s=arc-20160816; b=He6MTNqZaRl1geHWpz/7VbNiW/7jnJGozyOYcy/ACKGGvwznsSD/TKjgmG1Xcy3Gcg aBFiViqMls38/e8uSQY0+J4Z1mOpBYWFHti5OPNKl0GnzZ2LPRfMCVY6bqdKEPAJOEJz gMs3vFN4hw7au6YGlTTcUdvYE0svdzGXOpzqINUwhAs6tIq15Zp4wEdn17kkOQwmircS bunFGc2nfhhzC8FqlP4g4nxMTrJ9d8V93XxgeLf5nkVujlpxi0ev/VHtTBjx/3ZvbBgw gcfQ4w10e4aJdGWKF9x/u3EghNJuTYQCdGTI/uFxqt+Jih35N/yjPFQHvoGNFftZGvPg 2H2g== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=nfE/pHGFoOuV1vJVrjKS8q80ZE4BqLFL186Jz5O/TF8=; b=y2+X4u39UEM1rsKY995RXGxOrsIZ1liTKZygNrWzMpQ8VCeJOqXetbNe/sjNsj5RNI KZcq1SZH+1jigVsJaqgizKzr1C4QV6Mr4huascdz4xaMVe/xFyneY520pxR5qoTHDUkk /c6CqcH/yMTXTlXpjLYSgMJeEIQOmklQ75kOyH2S/JwincIn5vitJCp/6ej0bHYMN/bw A/Rz92QEIdeJxKiG7HH213CkNaO/cq9GxHMGUSjxinrr1gcgpyYP+v/QJUo6H0XKVh78 iV0x3WO+wDEpOijVXjU9KFDi7pJcMF7nMSUoCm89agDYaxqnYW3sMuxtCRv6fz5m7+O/ PS+g== 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 y3si16453308ede.38.2019.10.15.19.25.14; Tue, 15 Oct 2019 19:25:38 -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 S1732392AbfJOTkQ (ORCPT + 99 others); Tue, 15 Oct 2019 15:40:16 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:39076 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727856AbfJOTkQ (ORCPT ); Tue, 15 Oct 2019 15:40:16 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.2 #3 (Red Hat Linux)) id 1iKSg0-0002Pi-T2; Tue, 15 Oct 2019 19:40:12 +0000 Date: Tue, 15 Oct 2019 20:40:12 +0100 From: Al Viro To: Linus Torvalds Cc: Guenter Roeck , Linux Kernel Mailing List , linux-fsdevel , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , linux-arch Subject: Re: [PATCH] Convert filldir[64]() from __put_user() to unsafe_put_user() Message-ID: <20191015194012.GO26530@ZenIV.linux.org.uk> References: <20191011001104.GJ26530@ZenIV.linux.org.uk> <20191013181333.GK26530@ZenIV.linux.org.uk> <20191013191050.GL26530@ZenIV.linux.org.uk> <20191013195949.GM26530@ZenIV.linux.org.uk> <20191015180846.GA31707@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 15, 2019 at 12:00:34PM -0700, Linus Torvalds wrote: > On Tue, Oct 15, 2019 at 11:08 AM Al Viro wrote: > > > > Another question: right now we have > > if (!access_ok(uaddr, sizeof(u32))) > > return -EFAULT; > > > > ret = arch_futex_atomic_op_inuser(op, oparg, &oldval, uaddr); > > if (ret) > > return ret; > > in kernel/futex.c. Would there be any objections to moving access_ok() > > inside the instances and moving pagefault_disable()/pagefault_enable() outside? > > I think we should remove all the "atomic" versions, and just make the > rule be that if you want atomic, you surround it with > pagefault_disable()/pagefault_enable(). Umm... I thought about that, but ended up with "it documents the intent" - pagefault_disable() might be implicit (e.g. done by kmap_atomic()) or several levels up the call chain. Not sure. > That covers not just the futex ops (where "atomic" is actually > somewhat ambiguous - the ops themselves are atomic too, so the naming > might stay, although arguably the "futex" part makes that pointless > too), but also copy_to_user_inatomic() and the powerpc version of > __get_user_inatomic(). Eh? copy_to_user_inatomic() doesn't exist; __copy_to_user_inatomic() does, but... arch/mips/kernel/unaligned.c:1307: res = __copy_to_user_inatomic(addr, fpr, sizeof(*fpr)); drivers/gpu/drm/i915/i915_gem.c:313: unwritten = __copy_to_user_inatomic(user_data, lib/test_kasan.c:510: unused = __copy_to_user_inatomic(usermem, kmem, size + 1); mm/maccess.c:98: ret = __copy_to_user_inatomic((__force void __user *)dst, src, size); these are all callers it has left anywhere and I'm certainly going to kill it. Now, __copy_from_user_inatomic() has a lot more callers left... Frankly, the messier part of API is the nocache side of things. Consider e.g. this: /* platform specific: cacheless copy */ static void cacheless_memcpy(void *dst, void *src, size_t n) { /* * Use the only available X64 cacheless copy. Add a __user cast * to quiet sparse. The src agument is already in the kernel so * there are no security issues. The extra fault recovery machinery * is not invoked. */ __copy_user_nocache(dst, (void __user *)src, n, 0); } or this static void ntb_memcpy_tx(struct ntb_queue_entry *entry, void __iomem *offset) { #ifdef ARCH_HAS_NOCACHE_UACCESS /* * Using non-temporal mov to improve performance on non-cached * writes, even though we aren't actually copying from user space. */ __copy_from_user_inatomic_nocache(offset, entry->buf, entry->len); #else memcpy_toio(offset, entry->buf, entry->len); #endif /* Ensure that the data is fully copied out before setting the flags */ wmb(); ntb_tx_copy_callback(entry, NULL); } "user" part is bollocks in both cases; moreover, I really wonder about that ifdef in ntb one - ARCH_HAS_NOCACHE_UACCESS is x86-only *at* *the* *moment* and it just so happens that ..._toio() doesn't require anything special on x86. Have e.g. arm grow nocache stuff and the things will suddenly break, won't they?