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 X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADF2FC433E0 for ; Wed, 13 May 2020 19:36:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6154220671 for ; Wed, 13 May 2020 19:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589398600; bh=D+MMl1eEjVQMrzdkAuYYyV6dZOU0ShG86I8tDOXGHvg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=Hw43CrJlfno8dNHuFQffuUa2nYiL3L9X+XQaZDPisYaw8i489SehptMXFq/VREl+A M2bxa1ezS+p24YDydq4c//1ds8j2TbZN+0gd2SgOy1DssczTw/YruItjwyW5FKN8Rw KKC+/DV7WfuSI3+AiMcE1Aun/cz5xocXqOyB/cMU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387469AbgEMTgj (ORCPT ); Wed, 13 May 2020 15:36:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2389392AbgEMTgi (ORCPT ); Wed, 13 May 2020 15:36:38 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63756C061A0E for ; Wed, 13 May 2020 12:36:38 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id a9so518895lfb.8 for ; Wed, 13 May 2020 12:36:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jxiMveoP0RhCR8vjDCp/HmQWj731R3On/oP1uZF2PQE=; b=eyGhYtEXi8PPzZXswj9fBVzAZ7MKdPyfDFJANIY5Qa8lnG4B6PQlkLIvCnEsRuAYDd cijbLp3K6GqvurO+mnvtFYs9Cit1WsfsH6w5mAvZOtdvpGdoJxKX+co3FEMrxzMFBuxb 6U4kH5ee2J4uHKUOq+K6Hnjpw8SSIL615vIlE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jxiMveoP0RhCR8vjDCp/HmQWj731R3On/oP1uZF2PQE=; b=C/5IK4WLfxQxm8ktwonCY9v31YMQNP/AHGMG4ReltRVX7E7QZoq09ER6UFKU3hIRGB Bj5qHls6qt88fHUWxnAWZ8YYX66g87L9U50PUlhS1FKUQ3atgLm8Ho0xmCkfEI/Sm3ph cphVyuz5Vq/LuG8RzOjiokjyhh7oGYzd2EB6gqspg+ba6EBYxHTZEX6HTn7vz0RJIlBr l+lLHQhnYEEU3wpb9Ha1xfeSRoAP4uQQCKQIpj9SspvWbv+4JnWZzJdvlgZx+pnPoOHO pBrfQwGfrnD+fbYRipgtdXL7z8UZANlBoxHen0eSJLmZGNnxfMQN65pWXdJjuw5BYiVn 8Dfg== X-Gm-Message-State: AOAM5321gBbNearo6ps/wDeEdaO4wUescFK281BIrkMoDDEmBbAGOmx0 4YVBGitfqKpyPjKDo4mGqq1X9TBMXaA= X-Google-Smtp-Source: ABdhPJxvGYY8Tk8X8abTTyWljv8u2Q2gVeU+hMn1Oi0a/wM/kOxDSx0teUv8D3mCTCWfYqpJ5wWn0g== X-Received: by 2002:ac2:5dd5:: with SMTP id x21mr664473lfq.107.1589398596372; Wed, 13 May 2020 12:36:36 -0700 (PDT) Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com. [209.85.208.178]) by smtp.gmail.com with ESMTPSA id p6sm323280lfc.15.2020.05.13.12.36.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 May 2020 12:36:35 -0700 (PDT) Received: by mail-lj1-f178.google.com with SMTP id g4so925301ljl.2 for ; Wed, 13 May 2020 12:36:34 -0700 (PDT) X-Received: by 2002:a2e:9641:: with SMTP id z1mr394092ljh.201.1589398594575; Wed, 13 May 2020 12:36:34 -0700 (PDT) MIME-Version: 1.0 References: <20200513160038.2482415-1-hch@lst.de> <20200513160038.2482415-15-hch@lst.de> In-Reply-To: <20200513160038.2482415-15-hch@lst.de> From: Linus Torvalds Date: Wed, 13 May 2020 12:36:18 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 14/18] maccess: allow architectures to provide kernel probing directly To: Christoph Hellwig Cc: "the arch/x86 maintainers" , Alexei Starovoitov , Daniel Borkmann , Masami Hiramatsu , Andrew Morton , linux-parisc@vger.kernel.org, linux-um , Netdev , bpf@vger.kernel.org, Linux-MM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-parisc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org On Wed, May 13, 2020 at 9:01 AM Christoph Hellwig wrote: > > + arch_kernel_read(dst, src, type, err_label); \ I'm wondering if (a) we shouldn't expose this as an interface in general (b) it wouldn't be named differently.. The reason for (a) is that several users of the "copy_from_kernel_nofault()" interfaces just seem to want a single access from kernel mode. The reason for (b) is that if we do expose this as a normal interface, it shouldn't be called "arch_kernel_read", and it should have the same semantics as "get_user_unsafe()". IOW, maybe we should simply do exactly that: have a "get_kernel_nofault()" thing that looks exactly like unsafe_get_user(). On x86, it would basically be identical to unsafe_get_user(). And on architectures that only have the copy function, you'd just have a fallback something like this: #define get_kernel_nofault(dst, src, err_label) do { \ typeof (*src) __gkn_result; \ if (probe_kernel_read(&__gkn_result, src) < 0) \ goto err_label; \ (dst) = __gkn_result; \ } while (0) and now the people who want to read a single kernel word can just do get_kernel_nofault(n, untrusted_pointer, error); and they're done. And some day - when we get reliably "asm goto" wiith outputs - that "get_kernel_fault()" will literally be a single instruction asm with the proper exception handler marker, the way "put_user_unsafe()" already works (and the way "put_kernel_nofault()" would already work if it does the above). Linus 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 X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D8ADC433E1 for ; Wed, 13 May 2020 19:36:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CFD4E20671 for ; Wed, 13 May 2020 19:36:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="eyGhYtEX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CFD4E20671 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 828D180032; Wed, 13 May 2020 15:36:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DA198000B; Wed, 13 May 2020 15:36:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A0F780032; Wed, 13 May 2020 15:36:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 4EB1C8000B for ; Wed, 13 May 2020 15:36:39 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 03AA52C7C for ; Wed, 13 May 2020 19:36:39 +0000 (UTC) X-FDA: 76812702918.08.door75_571ac8c533f2a X-HE-Tag: door75_571ac8c533f2a X-Filterd-Recvd-Size: 5180 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 May 2020 19:36:38 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id l19so864764lje.10 for ; Wed, 13 May 2020 12:36:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jxiMveoP0RhCR8vjDCp/HmQWj731R3On/oP1uZF2PQE=; b=eyGhYtEXi8PPzZXswj9fBVzAZ7MKdPyfDFJANIY5Qa8lnG4B6PQlkLIvCnEsRuAYDd cijbLp3K6GqvurO+mnvtFYs9Cit1WsfsH6w5mAvZOtdvpGdoJxKX+co3FEMrxzMFBuxb 6U4kH5ee2J4uHKUOq+K6Hnjpw8SSIL615vIlE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jxiMveoP0RhCR8vjDCp/HmQWj731R3On/oP1uZF2PQE=; b=UHOmDTVvjYiGUp//Ldxhwv+vVv2pdGDk5oQqJOCCvjLhEfKtAsyTuKDuuWDwWiYcCW e7FZEZ6p9870PvUvJTsKhValu8c6fH92s0S+7ZE1DrZY3rVGvmFI4xvm0JTlHCC14bTn WBdGQH1ZqDrCe4/JedVRLgnegDYBJG8BVLcWLSD7ZVenJY07IiAk6t0vIwC7tZAy1sfU pxg0x1C0bola5SQQudPVsOQ1ztl63iRZFyI8TRTAjqd9DimI/b75wAmdgEAX0+FrTIqr V1Q/ZY90yfQqGCmKAn/01YRdTeTRTs6DpLtQL9bkxQLnkdcMxeZ6O/YrXPoxzH2gKJ8a riag== X-Gm-Message-State: AOAM5337i0cJM28JG+xHg55cvRCJjhCjJxscmreUzPUzDWXTYp3/ZLqw dvLffpMmCNAb1muxYO0aJlK10QPm24k= X-Google-Smtp-Source: ABdhPJz3m5+QK5xlZhgg7hJ06F+y4laIyFsMWUNHBwwQ4Uw5frMxV6KJyDyAucTWjig66X7V2EmwVQ== X-Received: by 2002:a2e:9cc1:: with SMTP id g1mr380160ljj.261.1589398596277; Wed, 13 May 2020 12:36:36 -0700 (PDT) Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com. [209.85.208.176]) by smtp.gmail.com with ESMTPSA id q21sm370024lfe.0.2020.05.13.12.36.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 May 2020 12:36:35 -0700 (PDT) Received: by mail-lj1-f176.google.com with SMTP id u15so916374ljd.3 for ; Wed, 13 May 2020 12:36:34 -0700 (PDT) X-Received: by 2002:a2e:9641:: with SMTP id z1mr394092ljh.201.1589398594575; Wed, 13 May 2020 12:36:34 -0700 (PDT) MIME-Version: 1.0 References: <20200513160038.2482415-1-hch@lst.de> <20200513160038.2482415-15-hch@lst.de> In-Reply-To: <20200513160038.2482415-15-hch@lst.de> From: Linus Torvalds Date: Wed, 13 May 2020 12:36:18 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 14/18] maccess: allow architectures to provide kernel probing directly To: Christoph Hellwig Cc: "the arch/x86 maintainers" , Alexei Starovoitov , Daniel Borkmann , Masami Hiramatsu , Andrew Morton , linux-parisc@vger.kernel.org, linux-um , Netdev , bpf@vger.kernel.org, Linux-MM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, May 13, 2020 at 9:01 AM Christoph Hellwig wrote: > > + arch_kernel_read(dst, src, type, err_label); \ I'm wondering if (a) we shouldn't expose this as an interface in general (b) it wouldn't be named differently.. The reason for (a) is that several users of the "copy_from_kernel_nofault()" interfaces just seem to want a single access from kernel mode. The reason for (b) is that if we do expose this as a normal interface, it shouldn't be called "arch_kernel_read", and it should have the same semantics as "get_user_unsafe()". IOW, maybe we should simply do exactly that: have a "get_kernel_nofault()" thing that looks exactly like unsafe_get_user(). On x86, it would basically be identical to unsafe_get_user(). And on architectures that only have the copy function, you'd just have a fallback something like this: #define get_kernel_nofault(dst, src, err_label) do { \ typeof (*src) __gkn_result; \ if (probe_kernel_read(&__gkn_result, src) < 0) \ goto err_label; \ (dst) = __gkn_result; \ } while (0) and now the people who want to read a single kernel word can just do get_kernel_nofault(n, untrusted_pointer, error); and they're done. And some day - when we get reliably "asm goto" wiith outputs - that "get_kernel_fault()" will literally be a single instruction asm with the proper exception handler marker, the way "put_user_unsafe()" already works (and the way "put_kernel_nofault()" would already work if it does the above). Linus From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jYxBH-0002Dg-Jd for linux-um@lists.infradead.org; Wed, 13 May 2020 19:36:40 +0000 Received: by mail-lj1-x242.google.com with SMTP id u15so916583ljd.3 for ; Wed, 13 May 2020 12:36:38 -0700 (PDT) Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com. [209.85.208.175]) by smtp.gmail.com with ESMTPSA id z8sm315253lfb.44.2020.05.13.12.36.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 May 2020 12:36:35 -0700 (PDT) Received: by mail-lj1-f175.google.com with SMTP id u15so916372ljd.3 for ; Wed, 13 May 2020 12:36:34 -0700 (PDT) MIME-Version: 1.0 References: <20200513160038.2482415-1-hch@lst.de> <20200513160038.2482415-15-hch@lst.de> In-Reply-To: <20200513160038.2482415-15-hch@lst.de> From: Linus Torvalds Date: Wed, 13 May 2020 12:36:18 -0700 Message-ID: Subject: Re: [PATCH 14/18] maccess: allow architectures to provide kernel probing directly List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-um" Errors-To: linux-um-bounces+geert=linux-m68k.org@lists.infradead.org To: Christoph Hellwig Cc: Daniel Borkmann , linux-parisc@vger.kernel.org, Netdev , the arch/x86 maintainers , linux-um , Alexei Starovoitov , Linux Kernel Mailing List , Linux-MM , Masami Hiramatsu , Andrew Morton , bpf@vger.kernel.org On Wed, May 13, 2020 at 9:01 AM Christoph Hellwig wrote: > > + arch_kernel_read(dst, src, type, err_label); \ I'm wondering if (a) we shouldn't expose this as an interface in general (b) it wouldn't be named differently.. The reason for (a) is that several users of the "copy_from_kernel_nofault()" interfaces just seem to want a single access from kernel mode. The reason for (b) is that if we do expose this as a normal interface, it shouldn't be called "arch_kernel_read", and it should have the same semantics as "get_user_unsafe()". IOW, maybe we should simply do exactly that: have a "get_kernel_nofault()" thing that looks exactly like unsafe_get_user(). On x86, it would basically be identical to unsafe_get_user(). And on architectures that only have the copy function, you'd just have a fallback something like this: #define get_kernel_nofault(dst, src, err_label) do { \ typeof (*src) __gkn_result; \ if (probe_kernel_read(&__gkn_result, src) < 0) \ goto err_label; \ (dst) = __gkn_result; \ } while (0) and now the people who want to read a single kernel word can just do get_kernel_nofault(n, untrusted_pointer, error); and they're done. And some day - when we get reliably "asm goto" wiith outputs - that "get_kernel_fault()" will literally be a single instruction asm with the proper exception handler marker, the way "put_user_unsafe()" already works (and the way "put_kernel_nofault()" would already work if it does the above). Linus _______________________________________________ linux-um mailing list linux-um@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-um