Received: by 10.223.164.202 with SMTP id h10csp1011419wrb; Tue, 7 Nov 2017 19:46:00 -0800 (PST) X-Google-Smtp-Source: ABhQp+SNc4+P8m1GHMl6Z0eCGgGDk5VoEw4su+U0uPMrQKfRUCEPXUShXUeS20QRegpTN1FTWnfe X-Received: by 10.99.180.3 with SMTP id s3mr901792pgf.174.1510112760847; Tue, 07 Nov 2017 19:46:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510112760; cv=none; d=google.com; s=arc-20160816; b=nX2c2C/pOFiWrLUfIMEEgXsK+7zq1nTDQa8hrlEhUr7+0Lp9n2PaoawuXEMKIRw1ic lDWjXZHkbMMUkWHVKfK8/NU4w6x33vLFryQPSrf7bIwIBMH6q69qBLOmHwTD2sTXMCuT QoxXA0PO6dm20+0TQyoBGrLJHTti8U/5T0+w3y+tYZ15QXUswSvICp2xT+xN4MXON7b9 pNCWhr4JrCNDre6/5+YFVwpKI6kFxrQX7CTHQIoHmzCz0/jPtHIvi9L2xN6AuoEDBKnH RVINqZRkWniE6bBKBrxHJxPAmGTaHXx7BiXizPC+ESwOA06hCDyfrChtivYDod1gQHB3 6wGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=Fq7YmfljPVUb26djVjqFOVATba9Sp3YYMuSbGiobQrY=; b=T3qOSVvn43auBG9ZCLZiB2cOix43zuW2SIEeyzMdUm/LQ1DWMFQlfrZu+muTzeMbs2 9tX4IbqY+ueVqENtrrDU9ECBqboyeNDKK0PV+sfz7zeaYgHD5O8GhFDF/pkAl6v4mJbL HocYCZKDkobATbcl/eDmMYr8dIiE1BWYrOk7wKCo8h+9UMLqAQDV7bny84f+Zj56zEel dlouAKDB3+WmxE9v7zPUQjBQbhOqmeEQQrIETeUytuJAOeIni6lh0RdEqfNViUZS5gQH AnKG+O8YFVEQi+DC9WdnIwRAsJNm0H0b0yamWUYk8QvUAG5Hsp98I0OaU1v2zWnY6yr8 SePA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iggl9iBG; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si2557201pli.755.2017.11.07.19.45.48; Tue, 07 Nov 2017 19:46:00 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iggl9iBG; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757026AbdKHB0H (ORCPT + 90 others); Tue, 7 Nov 2017 20:26:07 -0500 Received: from mail-vk0-f65.google.com ([209.85.213.65]:48364 "EHLO mail-vk0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752749AbdKHB0F (ORCPT ); Tue, 7 Nov 2017 20:26:05 -0500 Received: by mail-vk0-f65.google.com with SMTP id y196so749060vkc.5; Tue, 07 Nov 2017 17:26:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Fq7YmfljPVUb26djVjqFOVATba9Sp3YYMuSbGiobQrY=; b=iggl9iBGgX/Uh/bbzmAh3FzolAALpoahHNFtLgkZUK3+TWFOQZDT5J56fBmLdzbJ9x 0nfv5W6yxE8iH37iKrxmxTdNbzHXTK/t6SYVOxA5T+MgxdzsdvrOD/pal/MQZuR9K9cI 2mkV+D5WjY8XFuhkOclqVHqai30lmxUXG3FYc4JnRVQOWxcdHN35jkQtn7T09bgZ/Bhv sFU3RN0VDNRuIF7qh8j+r0wVgXWrA4dJtaz18SqLDV96KcL1p+/bXzYd5jB0ZSZU3Cz4 Ih25u1wWlceeAy/7Eb5EmRidS4xRpkrYj5YP2Q2LYQz35YCLwXxdV3xqBxFD4plB9yzI ctcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Fq7YmfljPVUb26djVjqFOVATba9Sp3YYMuSbGiobQrY=; b=HMhhIQ1O3J7d7gPwnUrPPVNd+w5+QKy8b1E4XOxBXDbnVVQzjKonLEKZ47/uBiQlpX RV/a2K0x17iu17Vm4eeVH0l7YWtsV6AOoiooR1CRAgcP9CAuMjUg2qm6MdtfOdcXtoB8 3/xTAsNp8vQoOKSjlWlE+p+Fk+1xKmTyzzpjjQIgomavuLO0NtLLNOVIdIaKLmXMI8W7 AWth9bT9hYW4mafwfal8DTeMff86MEacaAgh4vCIqdAnKcFy20dvIIRbx7JHOBFGBnyw g+/1O/lD54kPJuZ3ch9JVPds33/1sC/hXU5tuQExLatXm+d/e8pp4SPEPTBXRgVzbj63 yPZg== X-Gm-Message-State: AJaThX7aadzJ41YJB0MMVueutPeZZI7t+y28q90K3QNi46zZjQILF7Bc huqQOe462R2rHwE6zs3jX/hthSPuf5aeYG4T/eU= X-Received: by 10.31.107.129 with SMTP id k1mr480001vki.159.1510104364530; Tue, 07 Nov 2017 17:26:04 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.210.14 with HTTP; Tue, 7 Nov 2017 17:25:23 -0800 (PST) In-Reply-To: <0b17e570-387b-2a4e-48c4-be87e6b2c4a4@oracle.com> References: <20171103065833.8076-1-sandipan@linux.vnet.ibm.com> <94a4761f-1b51-8b70-fb7f-3cea91c69717@fb.com> <1509815348.8zu63uatdo.naveen@linux.ibm.com> <4acdc081-341d-ee91-a591-b1d331a8c8d5@fb.com> <1509982000.092la4257a.naveen@linux.ibm.com> <1510042830.62prnydrlw.naveen@linux.ibm.com> <328c2dff-7d6d-0dc0-46cf-ae715845903e@fb.com> <0b17e570-387b-2a4e-48c4-be87e6b2c4a4@oracle.com> From: Y Song Date: Tue, 7 Nov 2017 17:25:23 -0800 Message-ID: Subject: Re: [RFC PATCH] bpf: Add helpers to read useful task_struct members To: atish.patra@oracle.com Cc: Alexei Starovoitov , "Naveen N. Rao" , netdev , Sandipan Das , Brendan Gregg , Daniel Borkmann , Martin KaFai Lau , Kees Cook , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 7, 2017 at 4:29 PM, Atish Patra wrote: > On 11/07/2017 04:42 PM, Y Song wrote: >> >> On Tue, Nov 7, 2017 at 2:04 PM, Alexei Starovoitov wrote: >>> >>> On 11/8/17 6:47 AM, Y Song wrote: >>>> >>>> >>>> On Tue, Nov 7, 2017 at 1:39 PM, Alexei Starovoitov wrote: >>>>> >>>>> >>>>> On 11/8/17 6:14 AM, Y Song wrote: >>>>>> >>>>>> >>>>>> >>>>>> On Tue, Nov 7, 2017 at 12:37 AM, Naveen N. Rao >>>>>> wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>> Alexei Starovoitov wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On 11/7/17 12:55 AM, Naveen N. Rao wrote: >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> I thought such struct shouldn't change layout. >>>>>>>>>> If it is we need to fix include/linux/compiler-clang.h to do that >>>>>>>>>> anon struct as well. >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> We considered that, but it looked to be very dependent on the >>>>>>>>> version >>>>>>>>> of >>>>>>>>> gcc used to build the kernel. But, this may be a simpler approach >>>>>>>>> for >>>>>>>>> the shorter term. >>>>>>>>> >>>>>>>> >>>>>>>> why it would depend on version of gcc? >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> From what I can see, randomized_struct_fields_start is defined only >>>>>>> for >>>>>>> gcc >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> = 4.6. For older versions, it does not get mapped to an anonymous >>>>>>> >>>>>>> >>>>>>> >>>>>>> structure. We may not care for older gcc versions, but.. >>>>>>> >>>>>>> The other issue was that __randomize_layout maps to __designated_init >>>>>>> when >>>>>>> randstruct plugin is not enabled, which is in turn an attribute on >>>>>>> gcc >>>>>>>> >>>>>>>> = >>>>>>> >>>>>>> v5.1, but not otherwise. >>>>>>> >>>>>>>> We just need this, no? >>>>>>>> >>>>>>>> diff --git a/include/linux/compiler-clang.h >>>>>>>> b/include/linux/compiler-clang.h >>>>>>>> index de179993e039..4e29ab6187cb 100644 >>>>>>>> --- a/include/linux/compiler-clang.h >>>>>>>> +++ b/include/linux/compiler-clang.h >>>>>>>> @@ -15,3 +15,6 @@ >>>>>>>> * with any version that can compile the kernel >>>>>>>> */ >>>>>>>> #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), >>>>>>>> __COUNTER__) >>>>>>>> + >>>>>>>> +#define randomized_struct_fields_start struct { >>>>>>>> +#define randomized_struct_fields_end }; >>>>>>>> >>>>>>>> since offsets are mandated by C standard. >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> Yes, this is what we're testing with and is probably sufficient for >>>>>>> our >>>>>>> purposes. >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> Just tested this with bcc. bcc actually complains. the rewriter >>>>>> is not able to rewrite prev->pid where prev is "struct task_struct >>>>>> *prev". >>>>>> I will change bcc rewriter to see whether the field value is correct >>>>>> or >>>>>> not. >>>>>> >>>>>> Not sure my understanding is correct or not, but I am afraid that >>>>>> the above approach for clang compiler change may not work. >>>>>> If clang calculates the field offset based on header file, the offset >>>>>> may not be the same as kernel one.... >>>>> >>>>> >>>>> >>>>> >>>>> why is that? >>>>> When randomization is off both gcc and clang must generate the same >>>>> offsets, since it's C standard. >>>> >>>> >>>> >>>> The patch changed compiler-clang.h, so gcc still do randomization. >>> >>> >>> >>> gcc_plugins are off by default and randomization will not be >>> turned on for any sane distro or datacenter that cares about >>> performance and stability. >>> So imo above compiler-clang.h patch together with bcc fix would >>> be enough. >> >> >> Agree that short time the suggested fix should be enough. >> Long time, disto could become "insane" someday :-) >> > > Yup it works with clang compiler & bcc hack. Thanks :). > I verified it with task_switch.py & runqlat.py. > > Are you going to push the bcc hacks to github repo ? I will need to have proper implementation than a hack. Yes, once done, will push into bcc repo. Should be done soon. > > Regards, > Atish From 1583465695464556139@xxx Wed Nov 08 03:09:24 +0000 2017 X-GM-THRID: 1583027203607239623 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread