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.7 required=3.0 tests=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 DBCE4C010A2 for ; Tue, 5 Nov 2019 10:45:47 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 94493206BA for ; Tue, 5 Nov 2019 10:45:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 94493206BA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=vt.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces+kernelnewbies=archiver.kernel.org@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.92.3) (envelope-from ) id 1iRwLJ-0005MA-Ep for kernelnewbies@archiver.kernel.org; Tue, 05 Nov 2019 05:45:45 -0500 Received: from omr2.cc.ipv6.vt.edu ([2607:b400:92:8400:0:33:fb76:806e] helo=omr2.cc.vt.edu) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1iRwJE-0002rX-PD for kernelnewbies@kernelnewbies.org; Tue, 05 Nov 2019 05:43:36 -0500 Received: from mr5.cc.vt.edu (smtp.ipv6.vt.edu [IPv6:2607:b400:92:9:0:9d:8fcb:4116]) by omr2.cc.vt.edu (8.14.4/8.14.4) with ESMTP id xA5AhY20009253 for ; Tue, 5 Nov 2019 05:43:34 -0500 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by mr5.cc.vt.edu (8.14.7/8.14.7) with ESMTP id xA5AhT4h018943 for ; Tue, 5 Nov 2019 05:43:34 -0500 Received: by mail-qt1-f197.google.com with SMTP id k53so22017776qtk.0 for ; Tue, 05 Nov 2019 02:43:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:in-reply-to:references :mime-version:content-transfer-encoding:date:message-id; bh=aWjk5VgR/sipAyFyo1Zl3LRcoqFoyZeRmFJEYeCtd5I=; b=XAku/Ltum4EtLpJUyY6EKBhFPGIM7Q+td12JNiGdQ/33y7l0EKYIE8PwHcgFBym9t5 x0/NHwT+Gqs2+3qtXrbB79NPmn1O2aofAgJxA1JaXa0mkOlbB8Fpx9S2hY/o9IREuauV F18R7YhbseTveuIFca33Bk3oILjrszOR++Jn8WNgH5EnN723nE6M7zem9ihG+1F+5W62 ITA1miW7pbchhaRI1/XLPks2YtgOHJH8MPaWsZpMtQ1N+NomxccVPGiPJ6BdyR2EHihX 0T4h74Aeig790liPDL6swk64sBLfSVD4K36Fvc+y/rZ9XCUNz+oUM8pdFloG5jMwPAEl dB+w== X-Gm-Message-State: APjAAAWHynqWLTLSeF0ShLD7e6PHg5yd4lfu/rHYO2UBJV/WAStlZkyg j6Q+4dLCCAVqfHwlJH4L/QDOYhHzA0y8qejpYxZGN62EYMwJtz6m84k+hPdsAJcn/bt6DtgGkLD k4X6yQjMWLaSi8UvQPMCLeD/afgoZZdokL4SGlPU= X-Received: by 2002:a37:6642:: with SMTP id a63mr5419510qkc.462.1572950609139; Tue, 05 Nov 2019 02:43:29 -0800 (PST) X-Google-Smtp-Source: APXvYqw+fbdjxC44IbsCKqLdmpn3Exulz28sysC5SO3WKEEoq47GWB70dOopmfwdBy+Q+bIGK80PVQ== X-Received: by 2002:a37:6642:: with SMTP id a63mr5419496qkc.462.1572950608638; Tue, 05 Nov 2019 02:43:28 -0800 (PST) Received: from turing-police ([2601:5c0:c001:c9e1::359]) by smtp.gmail.com with UTF8SMTPSA id i4sm8251768qtp.57.2019.11.05.02.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2019 02:43:27 -0800 (PST) From: "Valdis Kl=?utf-8?Q?=c4=93?=tnieks" X-Google-Original-From: "Valdis Kl=?utf-8?Q?=c4=93?=tnieks" X-Mailer: exmh version 2.9.0 11/07/2018 with nmh-1.7+dev To: Irfan Ullah (울라 이르판) Subject: Re: Netlink socket returns NULL in vmx.c kernel file In-Reply-To: References: <694299.1571809092@turing-police> <20191105072232.GC2587462@kroah.com> Mime-Version: 1.0 Date: Tue, 05 Nov 2019 05:43:26 -0500 Message-ID: <219753.1572950606@turing-police> Cc: Greg KH , Linux Kernel List X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============4497534325532543358==" Errors-To: kernelnewbies-bounces+kernelnewbies=archiver.kernel.org@kernelnewbies.org --===============4497534325532543358== Content-Type: multipart/signed; boundary="==_Exmh_1572950606_14215P"; micalg=pgp-sha1; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit --==_Exmh_1572950606_14215P Content-Type: text/plain; charset=us-ascii On Tue, 05 Nov 2019 17:59:43 +0900, Irfan Ullah said: > Thank you for the response. > Attached are the files for kernel-user spaces communication. > //when I remove this wait the code does not work > msleep(3000); If your code doesn't work, but sticking in random delays makes it start working, you almost certainly have a race condition or synchronization issue that should be fixed using proper locking. > void hello_exit(void) > { > //netlink_kernel_release(nl_sk); Congratulations. You just leaked a socket here, which is going to make it difficult to use that socket until you either reboot or find a way to close it properly before trying to create it again. > (code generates some warnings, but it is not severe and could be ignored for the time being). You should do the following: 1) Understand your code well enough so you understand *why* the compiler issued the warning. 2) Correct your code so the compiler doesn't complain. It almost certainly understands C better than you do. gcc 9.2.1 emits one warning on the kernel module code at default warning levels. And it's one you *really* need to fix, because it indicates that you and the compiler are not on the same page about what types your variables are. Since it's going to go ahead and generate code based on what types *it* thinks your variables are, you will have nothing but pain and anguish debugging if you thought they were some other type.... In fact, you may want to compile the kernel module with 'make W=1' to get more warnings. If your system has sparse, you should use 'make W=1 C=1'. And all the warnings this generates are things that shouldn't be seen in clean kernel code. I didn't bother looking closely at your userspace. I gave up when I saw this: 14 int sock_fd; (...) 68 void user_space_receiver() 69 { (...) 96 user_space_receiver(sock_fd); There's 2 basic ways to pass a variable to a function. You're trying to use both of them here. Pick one and use it properly. Oh - and there's no possible way to reach the close(sock_fd); on line 77, because the rest of the function infinite loops without a break. At the very least, you should be checking the return code from recvmsg() and exiting the while(1) loop if there's an issue. Bottom line: You need to get a *lot* more experience writing proper C code in userspace before you try to write kernel code. --==_Exmh_1572950606_14215P Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Comment: Exmh version 2.9.0 11/07/2018 iQIVAwUBXcFSTQdmEQWDXROgAQJWYA//TPRr8O52cx8htfwW1/wNb9k9Z+ZaEUCi 0TkbV4LrSA0ehJC7CWaaaA/IwQIL9nOHkxJj+WyK91a9oCf2WXXqjaiwu1AlCORT txcmiXpaw4dD5NigavR2RYGsnz96a4BYbXuHvAsaP3qwVsqJr5LJgSDNHOJYn37R NfqlYcGc+IIwaxgJLzbrENf90D4ZLDIoSvRqGexxRIjiXqS38XRuslzsrHQmbVcv uARWsT850NqzcZvttlH5XJwGyRhCbGz+fkrCl0cA4S/8tdvRArbXXJlc9ANkzUgD VjV+WbmE53Toyd+uN9eKtAuFP3GCOPgYgMjLJn8Kb1EiudRoTiVKU9Iqon6cu9Oe T3Ko5uLvyMa/cMFh2iDS5H8AuoKom/+0AgwO4njiRsC8dlZYJSKICfs8Z7sIXucM Kgr1y+vb26fIZq7eUt5FTytn4tLKB35HlXkz1SI6T/6pcC8JZayqd26/LM/rL163 aZK/tGGHa1DfNl25JjoOSdNHdUCTHIcIVLzRj1d58WdFH8AB8L4W9udxKkhvzjUV PW3A3aHiAWrao3MJu0qr3DaLlDFr+jW2PnUIQ1tq2Xolkx+gr7m+LK4fuygdsFnT TUEWhS9BDs8L1i77kXN9Wp4J3rg1C0bJ4/sFTagHL2r+m3K9GsYD+VYHQjB0UJPF WrG6bjDdv90= =85lJ -----END PGP SIGNATURE----- --==_Exmh_1572950606_14215P-- --===============4497534325532543358== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============4497534325532543358==--