Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp149924ybm; Thu, 28 May 2020 18:48:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWxAg95qG/76WqhEePblgfl0BcVugdh0Powfgg7cg2cWsDwvs71nrp5Yg/R0uOW0/wlMDj X-Received: by 2002:aa7:c158:: with SMTP id r24mr6258943edp.341.1590716904858; Thu, 28 May 2020 18:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590716904; cv=none; d=google.com; s=arc-20160816; b=iifX3LWTS0ZUiWbyxzLl6LhygfDYeP70WZmLt6YjIKZUDoD4t1ZV5ipzHNZMTAplM4 dcjOYhNUXD9Rwh2wyQsvhZlmOTZKTPrx4QRL6qLWBfJpiP839D6zYY7CjNyJFO62ZxMp vXYvqnlYdp5Lxtle9ZidUGZp2PoLOjKY4pPcvY57pbKdfRiHbws7AF7htwtzknzJdYlg fDlzmuh78XT8hQN7SZ9Jnrf1FcJOskT2IDPiJXwbVEJeiF1Neu7A0D8nEE68oVNhhwmr LizvkwbDYHZ0QkKMNES4kI2PgJKHjAxdEDtVMhgnXRnxZ3bKRyPXgnFQcT3W7eo0bBnL lbKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=FWoWaWY5KM23AYzWVy94Ib6AwRh0YS5J0NG11YqB1Pw=; b=07VbVR7zPC787mT0AMWHQ+Z21X7VutuofWgvGsGrPC68jK2Cb+mRDQtqplBAFWIqqz lkJYoIPlosg5b24jxSFPjKvKt041w8KDZj4p7VrHMRzbBHYa/RO+zzok/cAN5AxLU1t/ 3vq/4aQi2FqfveVfsXIxO6H+oHxNW4QrkNlcLNgXPlSXl3sjGGh0TdUn5vUkto8UIAtK afIfmKxEe++uJFEKJQ4V0c6mfRh5jVrxqzbnInpwaBJ9PwrW+TBnIlVieATBP4ghHpKa BihdRW2rZFc2miwuBtHJnEmfCZMf+w/+9bP7TnhZaMDMSlh5CGg3lvnYTV6/KWCXgmrE y4Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=ljwfIphn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a9si4293986edy.372.2020.05.28.18.48.02; Thu, 28 May 2020 18:48:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=ljwfIphn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391050AbgE2Bpa (ORCPT + 99 others); Thu, 28 May 2020 21:45:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391005AbgE2Bp0 (ORCPT ); Thu, 28 May 2020 21:45:26 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 516D6C08C5C6 for ; Thu, 28 May 2020 18:45:26 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id c185so869527qke.7 for ; Thu, 28 May 2020 18:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=FWoWaWY5KM23AYzWVy94Ib6AwRh0YS5J0NG11YqB1Pw=; b=ljwfIphn/IgE4EWe2g3dD1aTEVtSiCe28jc71XALkBNVurxJTaUKPOWXJhBdc4ksxQ GLKylVYSvSf3odCukxIoQGuZbsMSBCEJgIjkR01Nts202IxxdTVfUruXv4yA31zXmQll 72jnxMvLntlO+c43FidSQdq8hndV0B2y2/c4E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=FWoWaWY5KM23AYzWVy94Ib6AwRh0YS5J0NG11YqB1Pw=; b=LnjL/hFCaB6/pctUOfWLqIPf/zxvgsYE4XBIcC5VwgwlM1DjxnH0Kwhqp1DKmp1f5j WJEuEIS2BD0WH1yNgFuGLP+pJvD85ohHmTjeKw+EeNuO85m0VF0L6GTvnSrseleMJDzT /YdYNTwh4TKYkLLxLCkflPoUBeb3jFlmmP9lzYhJ1uSYRjAomtd0iDCI7AHgI8dCyyg6 Ghy/NZwSEwn93e+MNNSMnkzo2iYXcVwOcpdOOkhzOSCk3Cl0oYs/nwdDv7ghXUkKMJYR NKRK0U+2v64Wlp3FyJXXwBjCvDiGcQjYisqqlUg3EVjmUTptFiBb3VdvxuHty4AW6VVp QWvA== X-Gm-Message-State: AOAM532HEcP2sr+oX/AwAu9WUqUAzwc/pRLQfCP/B0AsU0WoLV/BIYQq RAcDwv6DvcCiqI79rHk7p9DDJA== X-Received: by 2002:ae9:e703:: with SMTP id m3mr5733051qka.114.1590716725268; Thu, 28 May 2020 18:45:25 -0700 (PDT) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id a5sm4396685qtw.22.2020.05.28.18.45.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2020 18:45:24 -0700 (PDT) Date: Thu, 28 May 2020 21:45:24 -0400 From: Joel Fernandes To: Linus Torvalds Cc: Linux Kernel Mailing List , Matthew Blecker , Jesse Barnes , Mike Frysinger , Christian Brauner , vpillai , vineethrp@gmail.com, Peter Zijlstra , stable , Greg Kroah-Hartman , mingo@kernel.org Subject: Re: [PATCH] sched/headers: Fix sched_setattr userspace compilation breakage Message-ID: <20200529014524.GA38759@google.com> References: <20200528135552.GA87103@google.com> <20200528230859.GB225299@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 28, 2020 at 04:23:26PM -0700, Linus Torvalds wrote: > On Thu, May 28, 2020 at 4:09 PM Joel Fernandes wrote: > > > > > So no, this patch is fundamentally wrong. It negates the whole point > > > of having a uapi header at all. > > > > Sorry, I naively assumed that headers in 'include/uapi/' are safe to include > > from userspace. I feel terrible. > > Well, they "kind of" are safe to include. > > It's just that normally they are meant for system integrators to > include as part of the system header files. So they are designed not > to be safe for normal programs, but for library writers. > > And to make things more confusing, sometimes people _do_ include > kernel header files directly, just because they want to get features > that either haven't been exposed by the system libraries, or because > the system libraries copied the uapi header files for an older version > of the kernel, and you want the shiny new feature, so... > > And some of those header files are easier to do that with than others... Got it. Thank you Linus for the detailed reply, I really appreciate that. > > The problem is still does not get us 'struct sched_attr' even > > though the manpage of sched_setattr(2) says including is all that's > > needed. > > Ouch. But clearly you get it from -somewhere- since it then complains > about the double declaration. > > Strange. The reason is, since did not provide struct sched_attr as the manpage said, so I did the include of uapi's linux/sched/types.h myself: #include // inclusion of this header to get struct sched_attr will break due to // another structure struct sched_param redefinition. #include glibc's already defines struct sched_param (which is a POSIX struct), so my inclusion of above which is a UAPI header exported by the kernel, breaks because the following commit moved sched_param into the UAPI: e2d1e2aec572a ("sched/headers: Move various ABI definitions to ") Simply reverting that part of the patch also fixes it, like below. Would that be an acceptable fix? Then I can go patch glibc to get struct sched_attr by including the UAPI's . Otherwise, I suspect glibc will also break if it tried to include the UAPI header. If this is the wrong fix still, I'm sorry and I'll continue to research the solution. > > Also, even if glibc included 'include/uapi/linux/sched/types.h' to get struct > > sched_attr's definition, we would run into the same issue I reported right? > > The 'struct sched_param' is already defined by glibc, and this header > > redefines it. > > That's kind of the point: glibc sets up whatever system headers it > wants. The uapi ones are there to _help_ it, but it's not like glibc > _has_ to use them. > > In fact, traditionally we didn't have any uapi header files at all, > and we just expected the system libraries to scrape them and make > their own private copies. > > The uapi headers are _meant_ to make that easier, and to allow system > headers to then co-exists with the inevitable "I need to get newer > headers because I'm using a bleeding edge feature that glibc isn't > exposing" crowd. > > Put another way: a very non-portable programs _could_ include the uapi > headers directly, if the system library headers were set up that way. This might be painful for struct sched_attr because new attributes keep getting added to it, so having the UAPI help glibc and other libcs in this regard might be attractive. ---8<----------------------- From: "Joel Fernandes (Google)" Subject: [PATCH] sched/headers: Fix sched_setattr userspace compilation This is a partial revert of e2d1e2aec572a to fix the following. On a modern Linux distro, compiling the following program fails: #include #include // pthread.h includes sched.h internally. #include // inclusion of this header to get struct sched_attr will break due to // struct sched_param redefinition. #include void main() { struct sched_attr sa; return; } Compiler errors are: /usr/include/linux/sched/types.h:8:8: \ error: redefinition of ‘struct sched_param’ 8 | struct sched_param { | ^~~~~~~~~~~ In file included from /usr/include/x86_64-linux-gnu/bits/sched.h:74, from /usr/include/sched.h:43, from /usr/include/pthread.h:23, from /tmp/s.c:4: /usr/include/x86_64-linux-gnu/bits/types/struct_sched_param.h:23:8: note: originally defined here 23 | struct sched_param | ^~~~~~~~~~~ This also causes a problem with using sched_attr in Chrome. The issue is sched_param is already provided by glibc. Fixes: e2d1e2aec572a ("sched/headers: Move various ABI definitions to " Signed-off-by: Joel Fernandes (Google) --- include/linux/sched.h | 5 ++++- include/uapi/linux/sched/types.h | 4 ---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index fc2d2ede2d9ef..e6917b9d919fd 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -55,13 +55,16 @@ struct robust_list_head; struct root_domain; struct rq; struct sched_attr; -struct sched_param; struct seq_file; struct sighand_struct; struct signal_struct; struct task_delay_info; struct task_group; +struct sched_param { + int sched_priority; +}; + /* * Task state bitmask. NOTE! These bits are also * encoded in fs/proc/array.c: get_task_state(). diff --git a/include/uapi/linux/sched/types.h b/include/uapi/linux/sched/types.h index c852153ddb0d3..f863e747ff5f8 100644 --- a/include/uapi/linux/sched/types.h +++ b/include/uapi/linux/sched/types.h @@ -4,10 +4,6 @@ #include -struct sched_param { - int sched_priority; -}; - #define SCHED_ATTR_SIZE_VER0 48 /* sizeof first published struct */ #define SCHED_ATTR_SIZE_VER1 56 /* add: util_{min,max} */ -- 2.27.0.rc0.183.gde8f92d652-goog